#------# Begin code for test_open3.pl #!c:/apps/perl/bin/perl use IPC::Open3 qw( open3 ); use strict; use warnings; $| = 1; open DBG, ">debug2.log" or die $!; eval { my @pids; my @cmd1 = ( 'c:/Program Files/TortoiseSVN/bin/svn.exe', '--version', '-- quiet'); my $nul = $^O eq 'MSWin32' ? 'nul' : '/dev/null'; open(CHILD_STDERR, '>', 'error.txt') or die "Could not open CHILD_STDERR for writing ($!)"; open(CHILD_STDOUT, '>', 'out.txt') or die "Could not open CHILD_STDOUT for writing ($!)"; push @pids, open3(undef, '>&CHILD_STDOUT', '>&CHILD_STDERR', @cmd1); waitpid($_, 0) for @pids; print "Child exited with value ", $? >> 8, "\n"; #close(CHILD_STDIN) or die "Could not clost STDIN ($!)"; close CHILD_STDOUT or die "Could not close STDOUT"; open(CHILD_STDOUT, '<', 'out.txt') or die "Could not open CHILD_STDOUT for reading ($!)"; my @out = ; close CHILD_STDOUT or die "Could not close STDOUT ($!)"; close CHILD_STDERR or die "Could not close STDERR"; open(CHILD_STDERR, '<', 'err.txt') or die "Could not open CHILD_STDERR for reading ($!)"; my @err = ; close CHILD_STDERR or die "Could not close STDERR ($!)"; print "----OUT----\n", join("\n", @out), "----OUT----\n"; print "----ERR----\n", join("\n", @err), "----ERR----\n"; print DBG "Done!\n"; }; if ($@) { print DBG $@; close DBG; exit 1; } close DBG; #------# #### #------# begin code for test9.pl #!c:/apps/perl/bin/perl use IPC::Open3 qw( open3 ); use strict; use warnings; open DBG, ">debug2.log" or die $!; eval { my @cmd1 = ( 'c:/Program Files/TortoiseSVN/bin/svn.exe', '--version', '--quiet'); print "Running ", join(" ", map { "'$_'" } @cmd1), "\n"; open my $old_stdout, '>&', STDOUT or die "Couldn't dup stdout! ($!)"; open my $old_stderr, '>&', STDERR or die "Couldn't dup stderr! ($!)"; open STDOUT, '>', 'out.txt' or die "Couldn't redirect stdout to file! ($!)"; open STDERR, '>', 'err.txt' or die "Couldn't redirect stderr to file! ($!)"; system(@cmd1); close STDOUT; close STDERR; open STDOUT, '>&', $old_stdout or die "Could not re-connect to stdout! ($!)"; open STDERR, '>&', $old_stderr or die "Could not re-connect to stderr! ($!)"; open FH, '<', 'out.txt' or die "Could not open out.txt! ($!)"; open FH2, '<', 'err.txt' or die "Could not open err.txt! ($!)"; my ($out, $err); { local $/; $out = ; $err = ; } close FH; close FH2; print "----OUT----\n", $out, "\n----OUT----\n"; print "----ERR----\n", $err, "\n----ERR----\n"; #print join("\n", @err), "\n"; }; if ($@) { print DBG $@; exit 1; } close DBG; #------# #### This is perl, v5.8.9 built for MSWin32-x86-multi-thread (with 13 registered patches, see perl -V for more detail) Copyright 1987-2008, Larry Wall Binary build 828 [294165] provided by ActiveState http://www.ActiveState.com Built Dec 8 2010 16:51:11 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.