use IPC::Open3; # Open output in parent open OUTFILE, '>', '/where/to/put/output' or do { die "error opening output file: $!"; }; # Spawn child inheriting parent input and redirecting all output my $pid = open3( '<&STDIN', '>&OUTFILE', undef, $impKorr, -cfgfile => $cfgfile, -dbuser => $USER, -dbpassword => $PWD ) or do { die "error spawning external process: $!"; }; # Close output in parent close OUTFILE or do { warn "error closing output file: $!"; }; # Reap child and determine return code my $rc = (waitpid($pid, 0) == $pid ? $? : undef);