I'm trying to pass an open TCP socket connection from a Perl program as the stdin and stdout to an external application on Windows, similar to what inetd in the Unix world does.
What I have tried:
"Replace" stdin and stdout by the socket using
open
orPOSIX::dup2
and calling exec:# $socket is an open TCP socket open STDIN, '<&', $socket or die "Unable to dup stdin: $^E"; open STDOUT, '>&', $socket or die "Unable to dup stdout: $^E"; close $socket; exec($program) or die "Unable to exec $command: $^E";
Use
IPC::open3
:my $pid = open3( '>&'.$socket->fileno, '<&'.$socket->fileno, '<&'.fileno(STDERR), $program); waitpid $pid, 0;
In both cases the executed program receives something that is not a socket (a pipe, perhaps?), which is a problem because it wants to use select
. On Windows select
works only on sockets.
What can I do to pass the socket to the external application?
By the way I'm using Strawberry Perl, not ActiveState.