I have an external exe program that reads from the stdin and produces a result. It works like the wc
program and reads until the EOF. (Or End of Stream, rather.)
Update: let me add one more piece of explanation: I'm basically trying to write an Erlang pipe.
I'm able to call the program in a batch file like echo 339371249625 | LookupProj.exe
but I want to be able to pass data to this from an Erlang gen_server
.
I've looked at Erlang Ports but I'm having trouble getting them to play nice. Here's what I have:
test(InputText) ->
P = open_port({spawn, "/ExternEvent/LookupProj.exe"}, [stream, exit_status, use_stdio,
stderr_to_stdout, in, out]),
IBin = list_to_binary(InputText),
%% io:format("~p~n",[I2]),
P ! {self(), {command, <<IBin/binary, <<26>>/binary>>}}, %% ASCII 26 = EOF
P ! {self(), {eof}}, %% ERROR -- how to close stdin of the cat process?
receive B -> io:format("~p",[B]) end.
I've tried using the eof
flag in open_port
to no help. (Not sure if this is the right flag?)
Where did I go wrong? Thanks!