pipe my $cin, my $pin; pipe my $pout, my $cout; pipe my $perr, my $cerr; $pin->autoflush(1); $cout->autoflush(1); $cerr->autoflush(1); my $pid = fork(); warn("Fork failed\n"),return unless defined $pid; if ($pid == 0) { # Child fork/TDE execute close $pin; open STDIN, "<&", $cin or die "Map fail (STDIN): $!, $?\n"; exit 1 if fileno(STDIN) != 0; close $pout; close STDOUT; open STDOUT, ">&", $cout or die "Map fail (STDOUT): $!, $?\n"; exit 1 if fileno(STDOUT) != 1; close $perr; close STDERR; open STDERR, ">&", $cerr or print("Map fail (STDERR): $!, $?\n"),exit 1; exit 1 if fileno(STDERR) != 2; exec $command; } # Parent fork/tester return 0 if eval { alarm $timeout; local $SIG{ALRM} = sub { kill 9, $pid; die "Calculation call failed to return with $timeout seconds\n"; }; close $cin; close $cout; close $cerr; close $pin; local $/; # Slurp my $content = eof $pout ? '' : <$pout>; my $error = eof $perr ? '' : <$perr>; alarm 0; unless ($content =~ /\S/) { if ($error =~ /\S/) { $error =~ s/^/\t/mg; $error =~ s/\s*$/\n/; die "No result returned; STDERR=\n$error"; } else { die "Case Aborted: No result, no error\n"; } } elsif ($error =~ /\S/) { $error =~ s/^/\t/mg; warn "$executable output to STDERR for $case$command\n$error"; } }