in reply to Catching STDIN and STDERR on the fly
It's hard. You need to avoid deadlocks. For example, you could be blocked reading from the child's STDOUT (pipe empty) when the child is blocked sending data to STDERR (pipe full).
You could use some help from the OS.
Unix uses a file-handle based system: IO::Select.
Windows uses a more general and flexible event based system: WaitForMultipleEvents. CreateFile can be told to signal an event when a handle needs servicing.
You could use threads if Perl is built with thread support.
You could make the handles non-blocking and poll them. You could still block writing to the child's STDIN, though.
You could use IPC::Run. IIRC, it has some support for this kind of I/O, but it's inefficient in Windows (since it attempts to model the unix system). It's interface is very simple if you know in advance what you want to send to the child (non-interactive), and IPC::Run3's is even simpler (but that's all it can do).
|
|---|