You can start that program independently or you could have the main program start it as below (in which case you would want to take out the outer while loop (replace while with if)):#!perl -w # usage: showerr.pl port use IO::Socket; use strict; $| = 1; $SIG{CHLD} = 'IGNORE'; my $localport = shift; my $socklisten = IO::Socket::INET->new(LocalPort => $localport, Listen => 2, Reuse => 1, Proto => 'tcp') or die "Cannot open sock on $localport: $!\n"; while (my $readport = $socklisten->accept) { print "Accepted new connection at ", scalar(localtime), "\n"; print while <$readport>; print "Connection closed at ", scalar(localtime), "\n"; }
Note that there's an awkward sleep() here to wait an undetermined time for the listener to start. This race condition could be fixed, but it might be simpler to just run the showerr program independently first.#!perl -w use IO::Socket; use strict; my $errsocket = "1999"; system("start showerr.pl 1999"); sleep(5); *STDERR = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "localhost:$errsocket", Timeout => 30, ) or die "cannot create socketremote: $!\n"; warn "This is a test"; print STDERR "testing\n"; sleep(10);
In reply to Re: Open a second DOS window
by Thelonius
in thread Open a second DOS window
by bart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |