[erlang-questions] escript questions

Per Hedeland per@REDACTED
Mon May 21 19:30:36 CEST 2007


"Kenneth Lundin" <kenneth.lundin@REDACTED> wrote:
>
>The answer is that there is no support in Erlang to produce output to STDERR.

Hm, maybe not "support", but it's certainly possible (I assume in
escript too though I haven't tried it):

$ erl -eval 'stderr:format("hello\n", []), halt()' > /dev/null
hello
$ cat stderr.erl
-module(stderr).
-export([format/2]).

format(Fmt, Args) ->
    Port = open_port({fd, 2, 2}, [out]),
    port_command(Port, io_lib:format(Fmt, Args)),
    port_close(Port).

(In real code you might want to keep the port open rather than doing
open/close each time - should be pretty cheap though, and you never
print much on stderr, right?:-)

--Per Hedeland



More information about the erlang-questions mailing list