I am tryinng to use port to open a program that reads until EOF from
stdin, and then write results to stdout ... i.e. something like the
unix wc command. I can't figure out how to close the stdin of the
spawned process:
wc(InputText) ->
P = open_port({spawn, "wc"}, [stream, exit_status, use_stdio,
stderr_to_stdout, in, out, eof]),
P ! {self(), {command, "hello world"}},
P ! {self(), {eof}}, %% ERROR -- how to close stdin of the cat process?
receive {P, X} -> X end.
Also, where can I find detailed documentation on open_port?
Appreciate any help.
Thanks,
-cktan
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
The documentation for erlang:open_port/2 is at
http://erlang.org/doc/man/erlang.html . The system commands without a
module name are within the erlang module. Consider using
erlang:port_command/2 rather than using ! directly, for better behavior.
- Michael
Without closing stdin of wc, wc never returns because it thought there
are more data coming.
wc(InputText) ->
P = open_port({spawn, "wc"}, [stream, exit_status, use_stdio,
stderr_to_stdout, in, out, eof]),
port_command(P, InputText),
%% P ! {self(), {eof}}, %% ERROR -- how to close stdin of the wc process?
receive {P, X} -> X end,
port_close(P).
wc("hello world"). %% blocks forever.
What I have done is use an intermediate shell script. I write EOF or some
similar marker to the port and the shell script closes the stdin for the
command it controls.
--
Anthony Shipman Mamas don't let your babies
a...@iinet.net.au grow up to be outsourced.