簡體   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