Question

I'm trying to hack together a little CLI for Windows and, inspired by James Smith's Elixirconf talk, I was trying to use a Port to drive the interaction. So this is what I tried:

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"

The "clip" utility simply takes whatever is piped into it and puts it on Windows clipboard. If you were to call it from the command line, you'd call it like this

dir | clip

So as far as I can tell nothing's getting to the clipboard via my test. I just wanted to ask if I'm sending the input to the stdio in the right fashion--I mean do I want to use send for that?

Interestingly if I do this:

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

I get this:

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

I can't tell if the IO is actually getting sent to clip or not but I just wanted to confirm I'm doing the command correctly.

Windows 7 SP1

Was it helpful?

Solution

You don't need :in and you need to pass to the port {:stream, :binary} to be able to send to it bare strings.

Also try using port_command instead of sending to the port pid. http://www.erlang.org/doc/man/erlang.html#port_command-2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top