繁体   English   中英

如何将IO发送到Erlang端口?

[英]How To Send IO To An Erlang Port?

我正在尝试为Windows编写一个小CLI,并且受到James Smith的Elixirconf谈话的启发,我试图使用端口来推动交互。 所以这就是我的尝试:

Interactive Elixir (0.14.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> p = Port.open({:spawn,"clip"},[:stderr_to_stdout, :in, :exit_status])
#Port<0.1048>
iex(2)> send(p,"This is a test")
"This is a test"

“剪辑”实用程序只需将管道中的任何内容放入其中并将其放在Windows剪贴板上。 如果你是从命令行调用它,你会这样称呼它

dir | clip

所以据我所知,没有什么可以通过我的测试进入剪贴板。 我只想问我是否以正确的方式将输入发送到stdio - 我的意思是我是否想使用send?

有趣的是,如果我这样做:

p = Port.open({:spawn, "clip"}, [:stderr_to_stdout, :exit_status]) #Note no :in parameter
send(p,"This is a test")

我明白了:

** (EXIT from #PID<0.45.0>) :badsig

我无法判断IO是否实际上被发送到clip但我只是想确认我正在执行命令。

Windows 7 SP1

您不需要:in并且您需要传递到端口{:stream, :binary}以便能够向其发送裸字符串。

还尝试使用port_command而不是发送到端口pid。 http://www.erlang.org/doc/man/erlang.html#port_command-2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM