How do I prevent escript from reading stdin?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I prevent escript from reading stdin?

Roger Lipscombe-2
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?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How do I prevent escript from reading stdin?

José Valim-2
IIRC you can pass the -noinput flag at the beginning of the escript:

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

José Valim
Skype: jv.ptec
Founder and Director of R&D


On Mon, Jul 1, 2019 at 1:17 PM Roger Lipscombe <[hidden email]> 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?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How do I prevent escript from reading stdin?

Magnus Henoch-7
In reply to this post by Roger Lipscombe-2
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

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How do I prevent escript from reading stdin?

Roger Lipscombe-2
In reply to this post by José Valim-2
On Mon, 1 Jul 2019 at 12:22, José Valim <[hidden email]> wrote:
>
> IIRC you can pass the -noinput flag at the beginning of the escript:
>
> #!/usr/bin/env escript
> %%! -noinput

Works. Thanks.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How do I prevent escript from reading stdin?

Jacob-2
In reply to this post by Roger Lipscombe-2
Hi,

On 7/1/19 1:16 PM, 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.

While this might look ugly, it has the advantage of clearly showing your
intention, even if the escript was not consuming stdin. At least if you
put code like that into a script, it will help a future reader (possibly
including the writer) a lot.

When using bash/dash, you could also explicitly just close stdin
explicitly by

     ./some-escript <&-
     ./not-escript

with a similar effect but perhaps (depending on taste) less ugly. (Other shells may also have a similar feature)

Jacob

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions