-module(test_erlport). -export([hello/1]). -define(LOG(Name, Value), io:format("DEBUG: ~s: ~p~n", [Name, Value])). hello(Name) -> % Spawn test_erlport.py script and open communication channels Port = open_port({spawn, "python -u test_erlport.py"}, [{packet, 1}, binary, use_stdio]), ReqData = term_to_binary({hello, Name}), % Send binary data to hello.py script % ?LOG("ReqData", Port), port_command(Port, ReqData), % Wait for reply from hello.py script receive {Port, {data, RespData}} -> % Convert binary data to term {ok, binary_to_term(RespData)} after 5000 -> {error, timeout} end.