[Pancutan-commits] r55 - pancutan/lib/Pancutan
tincho-guest at alioth.debian.org
tincho-guest at alioth.debian.org
Mon Aug 13 06:46:24 UTC 2007
Author: tincho-guest
Date: 2007-08-13 06:46:23 +0000 (Mon, 13 Aug 2007)
New Revision: 55
Modified:
pancutan/lib/Pancutan/Util.pm
Log:
Added support to return the stdout of the process in execute()
Modified: pancutan/lib/Pancutan/Util.pm
===================================================================
--- pancutan/lib/Pancutan/Util.pm 2007-08-13 06:19:11 UTC (rev 54)
+++ pancutan/lib/Pancutan/Util.pm 2007-08-13 06:46:23 UTC (rev 55)
@@ -32,9 +32,19 @@
}
sub execute {
my @argv = @_;
- my $res;
+ my($fd, $res, @out);
local $SIG{CHLD} = "DEFAULT";
- system(@argv);
+ my $pid = open($fd, "-|");
+ unless(defined $pid) {
+ die "Cannot fork: $!";
+ }
+ unless($pid) { # child
+ $main::i_am_a_fork = 1;
+ exec(@argv);
+ die "Cannot exec: $!";
+ }
+ @out = <$fd>;
+ close $fd;
if($? == -1) {
$res = "failed to execute: $!";
} elsif($? & 127) {
@@ -43,6 +53,7 @@
} elsif($?) {
$res = sprintf("child exited with value %d", $? >> 8);
}
+ return($res, @out) if(wantarray);
return $res;
}
sub mount {
More information about the Pancutan-commits
mailing list