4
我有一个外部exe程序从stdin读取并产生结果。它的工作方式与wc
程序相同,并读取到EOF。 (或流的结束,而宁愿)。Erlang Ports:与类似“wc”程序的接口?
更新:让我再添加一个解释:我基本上试图编写一个Erlang管道。
我可以在批处理文件中调用该程序,如echo 339371249625 | LookupProj.exe
,但我希望能够通过Erlang gen_server
将数据传递给该程序。
我看过Erlang Ports,但我很难让他们玩得很好。下面是我有:
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.
我使用eof
标志试图open_port
没有帮助。 (不知道这是否是正确的标志?)
我哪里错了?谢谢!