From: Yigang Wen Date: Thu, 7 Nov 2013 06:17:26 +0000 (+0800) Subject: update func my_system to get the output if needed X-Git-Tag: 0.11~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=390f6ef56aa3edfe3281e264c2931d16fb914920;p=tools%2Fdepanneur.git update func my_system to get the output if needed update function my_system to return the output of child process according to the context. Change-Id: I49d7adba181e3f31ee254c8f808672656eda6d10 --- diff --git a/depanneur b/depanneur index a20bd40..8ac7100 100755 --- a/depanneur +++ b/depanneur @@ -273,15 +273,24 @@ sub my_system { my $cmd = shift; debug("my_system: $cmd"); my $ret; - defined(my $pid=fork) or die "Can not fork: $!\n"; - unless ($pid) { + my @out = (); + + defined(my $pid=open(PIPE, "-|")) or die "Can not fork: $!\n"; + unless ($pid) { # Child + open(STDERR, ">&STDOUT"); exec ($cmd); exit -1; + } else { # Parent + while (my $line = ) { + print $line; + push @out, $line if wantarray; + } + waitpid ($pid,0); + $ret = $?; + close(PIPE); + + return wantarray ? ($ret, @out): $ret; } - waitpid ($pid,0); - $ret = WIFEXITED($?); - $ret = $?; - return $ret; } sub expand_filename {