From be3c5a0d84db7bcda3131808b2d90ff78140dfbc Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 28 Sep 2011 12:08:15 +0000 Subject: [PATCH] fix streaming mode output format git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10660 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Utils.pm | 50 +++++++++-------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index a7354f318..b02a53730 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -1058,58 +1058,30 @@ sub runcmd } my $outref = []; - if (!defined($stream) || (length($exitcode) == 0)) { # do not stream + if (!defined($stream) || (length($stream) == 0)) { # do not stream @$outref = `$cmd`; } else { # streaming mode my @cmd; push @cmd,$cmd; - my $outreferr = []; - my $cmdin; - my $cmdout; - my $cmderr = gensym; - my $cmdpid = open3($cmdin,$cmdout,$cmderr,@cmd); - my $cmdsel = IO::Select->new($cmdout,$cmderr); - close($cmdin); - my @handles; my $rsp = {}; my $output; my $errout; - while ($cmdsel->count()) { - @handles = $cmdsel->can_read(); - foreach (@handles) { - my $line; - my $done = sysread $_,$line,180; - if ($done) { - if ($_ eq $cmdout) { - if ($::CALLBACK){ - $rsp->{data}->[0] = $line; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 0); - } else { - xCAT::MsgUtils->message("I", "$line\n"); - } - $output .= $line; - } else { - if ($::CALLBACK){ - $rsp->{data}->[0] = $line; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 0); - } else { - xCAT::MsgUtils->message("I", "$line\n"); - } - $errout .= $line; - } - } else { - $cmdsel->remove($_); - close($_); - } + open (PIPE, "$cmd |"); + while () { + if ($::CALLBACK){ + $rsp->{data}->[0] = $_; + $::CALLBACK->($rsp); + } else { + xCAT::MsgUtils->message("D", "$_"); } + $output .= $_; } - waitpid($cmdpid,0); # store the return string push @$outref,$output; } - # now whether streaming or not process - if ($?) + # now if not streaming process errors + if (($?) && (!defined($stream))) { $::RUNCMD_RC = $? >> 8; my $displayerror = 1;