Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Anonymous Monk
on Dec 05, 2012 at 08:49 UTC ( #1007235=note: print w/ replies, xml ) Need Help??


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

I forgot to explain that "works" but leaves zombies which you can kill after sleep-ing for a while or a few iterations of  waitpid $kpid, WNOHANG;


Comment on Re^2: IPC::Open3 STDIN never sees eof on win32?
Download Code
Re^3: IPC::Open3 STDIN never sees eof on win32?
by Yary (Scribe) on Dec 05, 2012 at 12:11 UTC
    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.

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-08-30 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls