[erlang-questions] Re: how do I get escript to emit all output before exiting?
Håkan Mattsson
hm@REDACTED
Mon Apr 4 15:56:51 CEST 2011
On Mon, Apr 4, 2011 at 3:12 PM, Matthias Lang <matthias@REDACTED> wrote:
> Hi,
>
> I'm using R14B02, locally compiled, on an x86-64. I have this escript:
>
> #!/usr/bin/env escript
>
> main(_) ->
> Line = "This is a string which is not quite eighty characters long.\n",
> Log = [lists:duplicate(600, Line), "last line\n"],
> file:write_file("/tmp/syslog", Log),
> {ok, Bin} = file:read_file("/tmp/syslog"),
> io:put_chars([Bin, "\n"]),
> init:stop().
>
> I expect the last two lines of output to be:
>
> This is a string which is not quite eighty characters long.
> last line
>
> But this is what running the program actually looks like:
>
> ~ >./truncated_io
> This is a string which is not quite eighty characters long.
> [about 100 lines removed by me when writing this mail]
> This is a string which is not quite eighty characters long.~ >
>
> Running the same code as a module works as expected, i.e. I see
> every line of output.
>
> How do I get escript to reliably print everything? Up until today,
> I thought init:stop() was enough.
The problem is probably that init:stop() returns before all output has
been emitted.
Try:
init:stop(),
receive after infinity -> ok end.
/Håkan
More information about the erlang-questions
mailing list