repellent has asked for the wisdom of the Perl Monks concerning the following question:
got_it> line1 got_it> line2 got_it> line3 123 456
got_it> 123 got_it> 456
999 got_it> 777 got_it> 888 123 456
999 got_it> 777 got_it> 888 123 456
use strict; use warnings; use Socket; # UPDATE #2: added 2 lines below use Win32::Process; use Win32; my $bug_on = 1; sub _pipe_from_fork ($) { my $pid; # emulate pipe() my $WRITE; socketpair($_[0], $WRITE, AF_UNIX, SOCK_STREAM, PF_UNSPEC) and shutdown($_[0], 1) and shutdown($WRITE, 0) or return undef; if (defined($pid = fork())) { unless ($pid) { if ($bug_on) { # UPDATE #1: added 1 line below close(STDOUT); # XXX: BUG open(STDOUT, ">&", $WRITE) or die; } else { print $WRITE "$_\n" for qw(line1 line2 line3); } } } return $pid; } my $pid = _pipe_from_fork(my $READ); die unless defined($pid); if ($pid) { print "got_it> $_" while <$READ>; } else { # UPDATE #1: added 1 line below print `perl -le "print 777; print 888; print STDERR 999"`; # UPDATE #2: commented exec line and added Win32::Process::Create( +) #exec qw(perl -le), 'print 123; print 456' or die; Win32::Process::Create( my $obj, 'C:\\Perl\\bin\\perl.exe', 'C:\\Perl\\bin\\perl.exe -le "print 123; print 456"', # does not inherit filehandles? 1, NORMAL_PRIORITY_CLASS, "." ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32: Redirect STDOUT to socket
by BrowserUk (Patriarch) on Feb 09, 2009 at 10:01 UTC | |
by repellent (Priest) on Feb 09, 2009 at 17:50 UTC | |
by BrowserUk (Patriarch) on Feb 09, 2009 at 18:46 UTC | |
by repellent (Priest) on Feb 10, 2009 at 07:34 UTC | |
by BrowserUk (Patriarch) on Feb 10, 2009 at 14:58 UTC | |
| |
|
Re: Win32: Redirect STDOUT to socket
by juster (Friar) on Feb 09, 2009 at 07:54 UTC | |
by repellent (Priest) on Feb 09, 2009 at 08:24 UTC | |
|
Re: Win32: Redirect STDOUT to socket
by ikegami (Patriarch) on Feb 09, 2009 at 09:56 UTC | |
by repellent (Priest) on Feb 09, 2009 at 17:46 UTC |