Murcia has asked for the wisdom of the Perl Monks concerning the following question:
When i run the wrapper.pl, often it does $cmd (ls -al), listing the files in the shell, but sometimes not, no output! WHY?use strict; use IPC::Open3; use IO::Select; use Carp; my $cmd = "ls -al"; my $pid = open3( *cmdIn, *cmdOut, *cmdErr, $cmd) or die "can not open +$cmd $!"; print "\$pid $pid"; print "\n"; $SIG{CHLD} = sub { print "result: Status $? in $pid\n" if waitpid($pid, 0) >0 }; my $select = IO::Select->new(*cmdErr, *cmdOut); print cmdIn "\n\n$cmd\n"; close(cmdIn); my $input; while ( my @ready = $select->can_read()) { foreach my $fh ( @ready ) { if (fileno($fh) == fileno(cmdErr)) { process_errors(); } else { print "STDOUT: ", <$fh>; } $select->remove($fh) if eof($fh); } } # close (cmdOut); close(cmdErr); sub process_errors { my $select= IO::Select->new( *cmdErr ); my $input; while ( $select->can_read(0.1) ) { sysread *cmdErr, (my $line), 1024; last unless $line; $input.= $line; } croak "THERE: $input $cmd code" if $input =~ /error:/; carp "HERE: $input $cmd code" if $input; } { local $SIG {__WARN__} = sub { my $warning = shift ; # warning handler }; # commands }
When I use a cmd which needs a short time, it seems to fail more often??? for a long cmd not??? Best regards Murcia/home/murcia # ./wrapper.pl $pid 11685 <<<<< OK STDOUT: total 48 -rwxr-xr-x 1 murcia users 77 Dec 14 11:30 test.pl result: Status 0 in 11685 /home/murcia # ./wrapper.pl $pid 11687 <<<< not OK /home/murcia #
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ipc::open3 start process
by Corion (Patriarch) on Dec 14, 2004 at 11:26 UTC | |
by edan (Curate) on Dec 14, 2004 at 12:03 UTC | |
Re: ipc::open3 start process
by amw1 (Friar) on Dec 14, 2004 at 16:23 UTC | |
Re: ipc::open3 start process
by amw1 (Friar) on Dec 14, 2004 at 15:59 UTC | |
Re: ipc::open3 start process
by zentara (Cardinal) on Dec 14, 2004 at 16:00 UTC |