[erlang-questions] escript cutting output

Robert Virding robert.virding@REDACTED
Thu Nov 17 23:32:56 CET 2011


io:format/3 already exists, io:format(IoDev, FormatString, Args). This problem actually exists with all io functions as they work in the same way so adding an extra argument to io:format is not a good solution. A better solution would probably be to add an io:flush which flushes an IoDev and waits until everything has been written out. At least as far as it is possible for erlang to detect that everything has been flushed. 

Robert 

----- Original Message -----

> io:format sends to another Erlang process and returns immediately. If
> you then exit you can cause the emulator to die before the file
> process has fully flushed its data. You just need to stay alive long
> enough for the other process to do its work, it is not wrong,
> remember that Erlang is designed to be a concurrent/distributed
> system.
> I do, however, wish that there was an io:format/3 that is like
> io:format/2 but with one extra parameter at the end that lets you
> either pass in a positive integer or the atom infinite to wait that
> length of time and when it flushes it then returns (unless it times
> out first if not infinite), or you can pass in a pid (or pass in a
> {pid(), ref()}) and it will send a message to that process when the
> flush is complete. I wish we had a lot of io functions like that...
> On Nov 17, 2011 2:56 AM, "Samuel" < samuelrivas@REDACTED > wrote:

> > > Erlang IO is handled by a separate process. It is probably still
> 
> > > outputting when your escript exits.
> 
> > > Using "|cat" speed up the output.
> 
> > > Using timer:sleep() wait for it to finish.
> 
> > > Both are right. You are not doing anything wrong.
> 

> > My feeling is that using cat makes it work until I output enough so
> 
> > that cat isn't fast enough either. Anyway, it feels like a hack,
> 
> > basically I'm redirecting output to cat so that it could handle it
> 
> > because the escript fails at it.
> 

> > I disagree the sleep solution is right. That's waiting a fixed
> > period
> 
> > of time that turns out to be greater than the time I should really
> 
> > wait for the io system to finish flushing everything. One bad thing
> > is
> 
> > that I'm wasting a lot of time (the real escript run in a for loop
> > in
> 
> > a shell script) and other bad thing is that it can go wrong anyway
> > if
> 
> > I try to minimise the time I'm sleeping.
> 

> > I'd like a solution that allowed me to wait until the exact moment
> 
> > (roughly) all io has been done.
> 

> > Researching a bit more, if I use erl -eval instead of an escript
> > this
> 
> > example works as I expect:
> 

> > erl -eval 'io:format("~p~p~n", [lists:duplicate(100000, $a), b]),
> > halt(0).'
> 

> > The vm waits until io finishes before evaluating halt. But if I use
> 
> > -noshell then the output is cut again.
> 

> > Curiously, in the later case it work again if I use init:stop(0).
> 
> > instead of halt(0), so I thought that init:stop effectively waited
> 
> > until the io system had flushed everything, but that didn't work in
> > my
> 
> > escript either:
> 

> > erl -eval 'io:format("~p~p~n", [lists:duplicate(100000, $a), b]),
> 
> > init:stop().' -noshell
> 

> > So my current idea is to get rid of the escript, compile main into
> > a
> 
> > module and use erl -eval with init:stop from a shell script, but I
> 
> > still think it would be reasonable to be able to wait for io in
> 
> > escripts, it sounds weird otherwise.
> 

> > Best
> 
> > --
> 
> > Samuel
> 
> > _______________________________________________
> 
> > erlang-questions mailing list
> 
> > erlang-questions@REDACTED
> 
> > http://erlang.org/mailman/listinfo/erlang-questions
> 

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111117/b9896c75/attachment.htm>


More information about the erlang-questions mailing list