I am not understanding something about ports, and it could be that I do not understand Python and NodeJS.
First my setup:
Mac OSX
Elixir 1.8.1
Erlang 21
Python 3.7.2, also tried 2.7.2.
In addition I have read Outside Elixir too.
I wanted to communicate with a python script via an Elixir port. For learning, I wanted to do this directly rather than using some other library, e.g. ErlPort. After some head banging I am here ![]()
In Ruby, Python, and Node I have a very simple script that only prints out to stdout
Ruby
STDOUT.sync = truepyth
print(["asdf".bytesize].pack("N"))
puts("asdf")
Python
import sys
sys.stdout.write("4\n")
sys.stdout.flush()
sys.stdout.write("asdf\n")
sys.stdout.flush()
Node
process.stdout.write("4" + "\n");
process.stdout.write("asdf" + "\n");
From Elixir repl I am running
iex> Port.open({:spawn, cmd}, [:binary, {:packet, 4}, :use_stdio, :exit_status])
Where “cmd” is something like:
python <path_to_script>
and the like for Ruby and Node.
Now when I do that for the Ruby script and the run flush() I get the following:
iex> Port.open({:spawn, ruby_cmd}, [:binary, {:packet, 4}, :use_stdio, :exit_status])
#Port<0.11>
iex> flush()
{#Port<0.11>, {:data, "asdf"}}
{#Port<0.11>, {:exit_status, 0}}
:ok
Where “asdf” is the expected data.
For Python and Node I get:
iex> Port.open({:spawn, python_cmd}, [:binary, {:packet, 4}, :use_stdio, :exit_status])
#Port<0.12>
iex> flush()
{#Port<0.12>, {:exit_status, 0}}
:ok
As you can see there is no {:data, “asdf”} msg as I would expect when writing to stdout from python (similar for node).
I have tried a lot of variations on writing to stdout/stderr etc. to no effect.


















