I'm writing scripts that are basically wrappers for Linux shell commands. I want to be able to 1) print messages to screen along with say the first line of any STDERR, and 2) print messages, STDOUT, and STDERR to go to a file.
The best I've come up with is something like the followng, which doesn't include STDOUT... open (LOG, ">$locations{log_file}") or die "[fail]..."; #open (STDERR, ">&LOG") or die "[fail] Can't dup STDERR"; #open (STDOUT, ">&LOG") or die "[fail] Can't dup STDOUT"; select (LOG); $| = 1; # make unbuffered sys ("cp foobar baz", 'copy to baz', 0); sub sys { my ($cmd, $english, $fatal) = (@_, 1); feedback ($english); print LOG `$cmd 2>&1`; if ($? == '0') { feedback ("[okay] $cmd"); return 1; } else { feedback ("[fail] $cmd"); feedback ("[error] $!$^E"); $failed = 1; cleanup() if ($fatal==1); return 0; } } sub feedback { my $line = sprintf ("%s %s", (strftime "%H:%M", localtime), $_[0]); print LOG "$line\n"; $line = (substr $line, 0, 79)."\n"; $emailtext .= $line; print STDOUT $line; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]