[erlang-questions] how do I get escript to emit all output before exiting?

Matthias Lang matthias@REDACTED
Mon Apr 4 15:12:00 CEST 2011


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.

Matt



More information about the erlang-questions mailing list