I am writing a tool that is going to call a system process (in this case, Z3 solver) very frequently and I am having troubles setting this up.
What I want to do:
- Start a
/usr/bin/z3process with-inflag - Keep it alive as the process waits for the standard input
- Send some string to its
stdin - Read a line from its
stdout - Possibly goto 3
- Kill the process politely
What I tried so far:
os:cmd– this thing doesn't seem to supportstdin- Using
port, but either it doesn't match my usecase or I don't understand it. My attempt:
main() ->
process_flag(trap_exit, true),
Port = open_port({spawn, "z3 -in"}, [{packet, 2}]),
Port ! {self(), {command, "(check-sat)\n"}},
receive
X ->
X
end.
...but it leaves me waiting infinitely. However for some reason this works with cat.
At best I would like to wrap an os process with an Erlang process, but I allow some tradeofs and workarounds. What is the most idiomatic way of doing it?