in reply to Re: Windows weirdness after fork, dup2
in thread Windows weirdness after fork, dup2

Thanks Thelonius, but no luck. If I use:
open STDOUT, ">&SOCK_WRITE" or die "STDOUT: $!\n"; warn "fileno(STDOUT)=",fileno(STDOUT),"\n";
I find that it's not using the right file descriptor:
fileno(STDOUT)=3
so when I exec a new process it doesn't have the file handles hooked up right. For example, if I change the infinite sleep loop to actually run something:
exec('perl','-e','$|=1; while(1) { sleep(5); print q:The time is now : +,time,qq:\n:; };') or die "exec error: $!\n";
the output from the child goes to the console, not the socket. With dup2, it goes to the socket.

Replies are listed 'Best First'.
Re: Re: Re: Windows weirdness after fork, dup2
by Thelonius (Priest) on Mar 05, 2004 at 21:15 UTC
    What you can do is set up the child to forward the output of the command to the main parent through the socket:
    # child close(SOCK_READ); open CMD, "ipconfig|" or die "ipconfig: $!\n"; print SOCK_WRITE while <CMD>; exit(0);
      Ah, great idea! That worked. I had to add some kludginess to get CTRL-C to kill the grandchild process (and for some reason an INT signal wasn't enough, so I had to use KILL), but here's a final working version.