This may be a little overblown for what you need, but it will capture both the STDOUT and the STDERR to a log file, die if the program does not exist, and display the return code.
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Run qw( start pump finish );
open(LOG, '>', 'log') or die "Unable to open log: $!";
my ($in, $out);
my $h = start([ 'run_tool', '-f', 'test.tcl' ], \$in, \$out, \$out);
while($h->pump) {
print LOG $out;
$out = '';
}
$h->finish;
close(LOG);
print "Exit code was: " . $h->result . "\n";
You'll probably want to take a closer look at the
IPC::Run docs for more details on what all it can do. It also offers fairly flexible control over interactive programs if you want to do that in the future. I tend to use it over
open or
system any time I need to start doing anything more than just run the program.