# RETURNS: %OSexec = ( stdout => $stdout, stderr => $stderr pid => $pid ) sub OSexecute { my $execute = $_[0]; my $stdin = IO::Select->new(); # not sure what difference <&STDIN and \*STDIN have $stdin->add("\*STDIN"); my $din = IO::Handle->new(); $stdin->add($din); my $stdout = IO::Select->new(); $stdout->add(\*STDOUT); my $dout = IO::Handle->new(); $stdout->add($dout); my $stderr = IO::Select->new(); $stderr->add(\*STDERR); my $derr = IO::Handle->new(); $stderr->add($derr); my ( $pid, $val, $out, $err ); my ( @stdin, @stdout, @stderr ); my $debug = "false"; #$debug = "true"; if ( $debug =~ /true/i ) { print "OSify::Execute::OSexecute::\$execute = $execute\n"; } # Here is the actual execution eval { print "Executing $execute\n"; $pid = open3( $din, $dout, $derr, $execute ); print "Waiting for pidout\n"; # waitpid waits for the proces to exit # $val could be used as a means to determine status # while waiting if that functionality becomes needed. $val = waitpid(-1,0); #wait's for process to complete # Process the results # Standard Out my $line; my @stdout = <$dout>; foreach $line (@stdout) { chomp($line); $out = $out . $line; } if ( ! $out ) { $out = 1; } # Standard Error @stderr = <$derr>; foreach $line ( @stderr ) { chomp($line); $err = $err . $line; } if ( ! $err ) { $err = 1; } }; $@ && die "OSify::OSexecute died upon execution of\n$execute\nWith$@"; # Question remains what activity qualifies as draining the buffer? $din->flush(); $din->close; $dout->flush(); $dout->close; $derr->flush(); $derr->close; my %OSexec = ( stdout => $out, stderr => $err, pid => $pid, ); print "Execute Finished with @{[%OSexec]}\n"; return %OSexec; }