Hi, i wanted to use ipc::open3 to control a process, here is the code of wrapper.pl
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 run the wrapper.pl, often it does $cmd (ls -al), listing the files in the shell, but sometimes not, no output! WHY?
/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 #
When I use a cmd which needs a short time, it seems to fail more often??? for a long cmd not??? Best regards Murcia

In reply to ipc::open3 start process by Murcia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.