Is it possible to write to stdin of external process In Elixir? Is NIF the only option right now?
The process that started from Elixir, blocks and wait for user input:
pid = spawn(fn ->
System.cmd("sh", [
Path.join([System.cwd, "sh", "wait_for_input"]),
"Hello world"
])
end)
I would like to achieve something like that
IO.write pid, "Hello"
IO.write pid, "Hello again"
And this is the script
#!/bin/sh
while read data
do
echo $data >> file_output.txt
done
Port.open/2
andPort.command/3
. – Dogbertsh
and writing data to so I can reproduce the error?Port.command
should work:iex(1)> port = Port.open({:spawn, "sh"}, []); Port.command(port, "echo 1\n"); iex(2)> flush {#Port<0.1348>, {:data, '1\n'}}
. – Dogbert