Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

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


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

You child is suffering from buffering, this works for me (wait hangs, probably a bug)

perl -MIPC::Open3 -e " open3(\*IN,q{>&STDOUT},q{>&STDERR},qw[perl -pe +1 ]); print IN 666,$/; close IN; sleep 3 "

For some stuff see Does IO::Select work? Anywhere?, Bidirectional IPC with Expect and Passthrough, Windows, threads and IPC::Open3, IPC::Open3 failure on Win32, win32 open3 strangeness, IPC::Open3 and Win32

And maybe also waitpid on Win32 ... wait forever, wait is broken on win32?

If you don't need interactivity IPC::Run3 works well enough


Comment on Re: IPC::Open3 STDIN never sees eof on win32?
Download Code
Re^2: IPC::Open3 STDIN never sees eof on win32?
by Anonymous Monk on Dec 05, 2012 at 08:49 UTC
    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;
      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-10-23 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls