当我exit_status在下面的例子中没有调用open_port时它是不可用的:
Eshell V5.7.5 (abort with ^G)
1> P = open_port({spawn, "cat >bar"}, [stream, use_stdio]).
#Port<0.498>
2> port_command(P, "hello\n").
** exception error: bad argument
in function port_command/2
called as port_command(#Port<0.498>,"hello\n")
Run Code Online (Sandbox Code Playgroud)
但是,当我只是添加exit_status 并保留所有相同的工作时:
Eshell V5.7.5 (abort with ^G)
1> P = open_port({spawn, "cat >bar"}, [stream, use_stdio, exit_status]).
#Port<0.498>
2> port_command(P, "hello\n").
true
Run Code Online (Sandbox Code Playgroud)
从文档中我不了解行为的差异.
当你在cat >bar命令shell 中的文件中重定向输出关闭时stdout,Erlang只是在这种情况下关闭端口,因为端口尝试默认使用命令输出并关闭eof.解决问题的正确方法是使用out选项作为butter71已经建议.类似的选项out,exit_status,error_to_stdout告诉端口理会stdout.