Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
It appears to be some problems with Windows (e.g. possibly total inability to redirect IO from sockets) - does anybody knows about this? May be using IPC::open3 and IO::Select will help? Tested on Win98SE with ActiveState perl 5.8.0. Thanks in advance. (PS: I've searched entire google, and didn't find anything useful).#!/usr/bin/perl use strict; select(STDIN);$| = 1; select(STDOUT);$| = 1; print STDERR "starting interaction\n"; $! = ''; print "GET /\n\n"; print STDERR "printerr is $! " . fileno(STDIN) . ", " . fileno(STDOUT) + . "\n"; print STDERR "req sent\n"; $! = ''; while (<STDIN>) { my $v = $_; print STDERR "readerr is $!\n"; print STDERR $v; } print STDERR "readerr is $!\n"; print STDERR "done interaction\n"; ----------- I tried several versions of servers, and all behave the same: #------version1 - works fine on linux #!/usr/bin/perl use strict; use IO::Socket; my $conn = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "192.168.0.12", #change to any hos +tname PeerPort => 80, ) || die("can't connect"); open(STDIN,"<&" . $conn->fileno); open(STDOUT,">&" . $conn->fileno); system("$^X testfile-slave.pl"); print STDERR "done\n"; -------------------- #---------version2 - windows-specific #!/usr/bin/perl #use strict; use IO::Socket; my $conn = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "192.168.0.12", #use address of any web server here PeerPort => 80) || die("can't connect"); binmode($conn); open(STDIN,"<&" . $conn->fileno) || print STDERR "can't redir stdin\n" +; open(STDOUT,">&" . $conn->fileno) || print STDERR "can't redir stdout\ +n"; my $file = "testfile-slave.pl"; use Win32::Process; use Win32; my ($ProcessObj,$exitcode); if (Win32::Process::Create($ProcessObj, "$^X","$^X $file", 1, NORMAL_PRIORITY_CLASS,".")) { $ProcessObj->Wait(500000); $ProcessObj->Kill($exitcode); } else { print STDERR "failed executing $file\n"; }; print STDERR "done\n"; --------------------
BazB changed pre tags to code tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Redirecting input and output of child process to inet socket fails on Win32
by crabbdean (Pilgrim) on Feb 29, 2004 at 14:20 UTC | |
|
Re: Redirecting input and output of child process to inet socket fails on Win32
by esskar (Deacon) on Feb 29, 2004 at 23:22 UTC | |
|
Re: Redirecting input and output of child process to inet socket fails on Win32
by fuzzycow (Sexton) on Mar 01, 2004 at 14:22 UTC |