I want to use the PTY library to communicate with another local program.
I am running the example code and it seems to be deadlocking.
The example code calls this out as possible, and states:
"we will change the buffering type in the factor command, assuming that
factor uses stdio for stdout buffering.
If IO.pipe is used instead of ::open, this code deadlocks because
factor's stdout is fully buffered."
I take the above to mean that the example code has been written such that a
deadlock _won't_ occur, but I appear to be wrong. When I run the code it just
If I tweak the example code to send invalid input to factor then I get a
response on stderr immediately:
factor: ‘42\\n’ is not a valid positive integer
... at which point it continues to spin.
Are the docs wrong? Am I doing something wrong? What's happening here?
Here's a link to the example code:
And a more succint reproduction of the same problem (with the invalid input
IO.pipe do |r,w|
PTY.open do |m,s|
pid = spawn("factor", in: r, out: s)
w.puts('42\n') # intentionally invalid to demonstrate stderr