Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: IPC::Open3 STDIN never sees eof on win32?

by Yary (Pilgrim)
on Dec 05, 2012 at 12:11 UTC ( #1007281=note: print w/replies, xml ) Need Help??

in reply to Re^2: IPC::Open3 STDIN never sees eof on win32?
in thread IPC::Open3 STDIN never sees eof on win32?

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.

Replies are listed 'Best First'.
Re^4: IPC::Open3 STDIN never sees eof on win32?
by bulk88 (Priest) on Dec 05, 2012 at 19:35 UTC
    I think the problem *might be* Perl's very large buffer size, see pipe fork win32.
      Buffer size doesn't seem to be it, since I can turn on autoflush in the parent and see writes as they happen in the child. Also buffer size doesn't explain the child not seeing the parent close the pipe, and the child not seeing the parent exit.

      That node pipe fork win32 is good reading but the poster states "If I add a 'close($parent);' after 'print $parent "exit now\r\n\r";' it works."- which is what I have in the one-liner, closing the parent's end of the pipe after I print to it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007281]
[Discipulus]: damn I missed a possible employer for seconds..

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-04-20 19:00 GMT
Find Nodes?
    Voting Booth?