[erlang-questions] How do I prevent escript from reading stdin?

Magnus Henoch magnus@REDACTED
Mon Jul 1 13:26:38 CEST 2019


On 01/07/2019 12:16, Roger Lipscombe wrote:

> If I paste a sequence of commands into my terminal window...
>
>      ./some-escript
>      ./not-escript
>
> ...then not-escript never gets run, because (afaict), some-escript ate
> all of the input. If I paste the following:
>
>      ./some-escript </dev/null
>      ./not-escript
>
> ...then it's fine. But that's ugly.
>
> How do I prevent escript from reading stdin?

You can add a line to your escript to pass an emulator argument and make
it not read any input:

#!/usr/bin/env escript
%%! -noinput

main(_) ->
    io:format("hello world\n").

IIRC, the %%! line needs to be the second or third line in the file.

Regards,
Magnus




More information about the erlang-questions mailing list