Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file:read_file/1 missing 1st binary of /dev/stdin which comes from Unix pipe #8725

Closed
pojiro opened this issue Aug 16, 2024 · 2 comments
Closed
Labels
bug Issue is reported as a bug

Comments

@pojiro
Copy link
Contributor

pojiro commented Aug 16, 2024

Describe the bug

I wrote a escript like following,

#!/usr/bin/env escript
main(_) ->
  {ok, Binary} = file:read_file("/dev/stdin"),
  io:format("~s", [binary_to_list(Binary)]).

Then use it with Unix pipe like following

LC_ALL=c ping -c 1 example.com | escript pipe_test_with_file_read.erl

Above didn't put anything, but when changed the ping count option from 1 to 2, the result was printed without 1st ping.

LC_ALL=c ping -c 2 example.com | escript pipe_test_with_file_read.erl
64 bytes from 93.184.215.14 (93.184.215.14): icmp_seq=2 ttl=54 time=129 ms

--- example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 126.080/127.448/128.817/1.368 ms

To Reproduce

It's the same as the Bug section.

Expected behavior

It would be nice to be able to use /dev/stdin directly in a Unix pipe.
I'm an Elixir programmer, this issue comes from elixir-lang/elixir#13780

Affected versions

I just confirmed this with 27.0.1 .

Additional context

Nothing.

@pojiro pojiro added the bug Issue is reported as a bug label Aug 16, 2024
@garazdawi
Copy link
Contributor

If you add -noinput to you escript it will work. That is:

#!/usr/bin/env escript
%%! -noinput
main(_) ->
  {ok, Binary} = file:read_file("/dev/stdin"),
  io:format("~s", [binary_to_list(Binary)]).

@pojiro
Copy link
Contributor Author

pojiro commented Aug 16, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug
Projects
None yet
Development

No branches or pull requests

2 participants