Alas this doesn't fix the core problem of the subprocess hanging in the read loop. I'll modify the example a bit to make the misbehavior clearer, incorporating some of your suggestions & some from other nodes:
perl -MIPC::Open3 -MPOSIX=WNOHANG -e "open CPYOUT,'>&STDOUT';open CPYE
+RR,'>&STDERR';$pid=open3(\*IN,'>&CPYOUT','>&CPYERR','perl','-pe','END
+ {warn qq(Finished\n)}');close CPYOUT;close CPYERR;print IN 'Hello',$
+/;close IN;sleep 3;waitpid $pid,WNOHANG"
The one liner is getting long with it's new features:
The subprocess has an END block printing that it is done. In "real life" the sub-process reads all the input, then prints a bunch of output when it is done reading all the input. The purpose of this question is figuring out how get the subprocess to move beyond its read loop.
The parent is closing its copies of the output handles as suggested in another thread. We do see output on the screen, and the parent eventually exits anyway, so the child is not blocking on output.
Also added a waitpid, which doesn't reap, and I end up with a zombie process. Only it isn't truly a zombie, it is still waiting on stdin, active and parentless. Which explains why wait/waitpid "hang"- the child hasn't exited. |