stephens2k has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a script that will execute a process in the background, monitoring STDOUT and STDERR to obtain data, then print "QUIT" on STDIN to kill off the application. I'm developing on XP but this will run on *nix.
I'm attempting to use open3 and IO::Select to read both STDOUT and STDERR without blocking. It ain't working...
I'm open to other approaches here.
my ($read, $write, $error); my $pid = open3( $write, $read, $error, "$em_command &") || die ERROR. +" : Unable to execute "; write_log (DEBUG, "Maintenance Proxy pid = $pid"); # exception occured if ($pid =~ /^open3:/) { write_log (ERROR, $pid); exit 1; } my $sel = IO::Select->new(); $sel->add($read); dumpValue ($sel); print "---\n"; $sel->add($error); dumpValue ($sel); print "---\n"; my ($rh, $inStr); while(my @ready = $sel->can_read) { foreach my $handle (@ready) { if ($handle == $error) { my $numBytesRead = sysread($rh, $inStr, 1024); print "ERROR: $inStr"; } else { my $numBytesRead = sysread($rh, $inStr, 1024); print "INFO: $inStr"; } $sel->remove($handle) if eof($handle); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: open3 and IO::Select
by ikegami (Patriarch) on Nov 19, 2007 at 22:21 UTC | |
by ddunham (Initiate) on Nov 20, 2007 at 22:47 UTC | |
by Anonymous Monk on Apr 14, 2009 at 13:01 UTC | |
|
Re: open3 and IO::Select
by ikegami (Patriarch) on Nov 19, 2007 at 21:25 UTC | |
by stephens2k (Novice) on Nov 19, 2007 at 21:53 UTC | |
|
Re: open3 and IO::Select
by gloryhack (Deacon) on Nov 20, 2007 at 05:21 UTC | |
by BrowserUk (Patriarch) on Nov 20, 2007 at 05:39 UTC | |
by gloryhack (Deacon) on Nov 20, 2007 at 05:42 UTC | |
|
Re: open3 and IO::Select
by salva (Canon) on Nov 20, 2007 at 10:26 UTC | |
by stephens2k (Novice) on Nov 20, 2007 at 15:46 UTC |