#/usr/bin/perl # program to test open3() # module imports use strict; use warnings; use diagnostics; use IPC::Open3; use IO::Handle; use FileHandle (); # variable declarations my $pid; my $pid2; my @errors; my @output; my $pgp_command = "pgp --key-add temp_pgp_key.asc --with-private"; open (OUTPUT, ">&STDOUT") # output sent directly or die "Can't dup STDOUT to OUTPUT: $!\n"; open (ERROR, ">&STDERR") # error sent directly or die "Can't dup STDERR to ERROR: $!\n"; eval { $pid = open3(\*INPUT, \*OUTPUT, \*ERROR, $pgp_command) or die "could not run pgp command : $pgp_command : $!"; print INPUT "\n"; # wait for child to terminate with PID -1 but not in non-blocking mode? $pid2 = waitpid(-1,0); }; $@ && die "ERROR: $@\n"; # EVAL_ERROR print "process id : " . $pid . "\n"; print "exit value \$? : " . $? . "\n"; print "pid2 : " . $pid2 . "\n"; @output = or @errors = or die "Could not get response from PGP command : $pgp_command : $!"; foreach (@output) { print "output " . $_ . "\n"}; foreach (@errors) { print "error " . $_ . "\n"}; close INPUT; close OUTPUT; close ERROR;