use strict; use warnings; use HTTP::Daemon; use HTTP::Status; use HTTP::Response; use HTTP::Headers; use Win32::Process; my $listener = HTTP::Daemon->new( LocalAddr => '127.0.0.1', LocalPort => 2112, Listen => 5) || die ("Listener could not be created\n"); my $counter = 0; print "$$] Listener waiting for Requests on ".$listener->url."\n"; # This loop monitors the port for connections for(;my $c = $listener->accept; $c->close) { print "\n$counter] Accepted Connection\n"; binmode $c; spawn($c); } sub spawn { my $c = shift; # Make a backup of STDOUT and STDIN #open( STDOUT_BACKUP, ">&STDOUT" ); open( STDIN_BACKUP, "<&STDIN" ); # redirect my $socket_no = $c->fileno; open(STDIN, "<&$socket_no") || die $!; #open(STDOUT, ">&") || die $!; # where to ? $c->close; # Spawn process my $obj; Win32::Process::Create($obj, $^X, "$^X serverx.pl", 1, NORMAL_PRIORITY_CLASS, '.') || die "ERROR: failed to execute: $^X serverx.pl; ". Win32::FormatMessage(Win32::GetLastError()); # Redirect STDOUT to what it used to be... #open( STDOUT, ">&STDOUT_BACKUP" ); open( STDIN, "<&STDIN_BACKUP" ); # Close the backup of STDOUT #close( STDOUT_BACKUP ); close( STDIN_BACKUP ); print "spawned ".$obj->GetProcessID."\n"; }