Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Update...

This works great in Linux but now I'm trying to get it working in Windows. The problem is that Windows doesn't seem to have the process print to the pipe that's attached to stdout. The only thing I can gather from testing variations is that STDOUT is the same for both "processes" in Windows. If I sleep and let the child run first or don't restore STDOUT, the pipe works as designed. As soon as I restore STDOUT, the pipe is broken even though they are separate processes.

Is there any way of doing this in Windows?

print "before the pipe\n"; open $old_stdout, ">&STDOUT" or die "open: $!"; local(*WH); pipe $rh, WH; open STDOUT, ">&WH" or die "open: $!"; STDOUT->blocking(0); # write something to the pipe # and have some fork/exec'ed process write to the pipe (via stdout) if( fork() ) { open( STDOUT, ">&", $old_stdout ) or die "open: $!"; print STDERR "I'm the parent\n"; sleep 3; } else { exec( 'echo fubar' ); exit( 0 ); } close WH; my $out = <$rh>; print "got from pipe: $out"; # $out is empty since fubar printed to +the screen

In reply to Re^3: Forks, Pipes and Exec (file descriptors) by diabelek
in thread Forks, Pipes and Exec by diabelek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-16 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found