$SIG{INT} = sub { open my $fh, ">PleaseStop" or warn "open(PleaseStop): $!"; } #### my $outcome = qx/java MyClass param1 param2 param3 ... /; #### # When it's time to call... call call_command sub call_command { my $command = shift; my ($pid, $rd, $wt); { local $SIG{INT} = 'IGNORE'; $pid = open2($rd, $wt, $command); # From IPC::Open2 } my $outcome = join "", <$rd>; waitpid $pid, 0; return $outcome; }