in reply to Print STDOUT and STDERR to file and to screen
Update: Fixed a typo#!/usr/bin/perl use strict; use warnings; use diagnostics; open(LOG, '>', 'LOG_FILE') or die "Can't redirect stdout: $!"; open(CMD, 'ls |'); open(STDERR, '>&', STDOUT) or die "Can't redirect stderr: $!"; open(STDERR, '>', 'LOG_FILE') or die "Can't redirect stderr: $!"; print "LOG_FILE\n"; while (<CMD>) { &lprint ($_) } sub lprint { my ($line) = @_; print LOG $line; print $line; } close(CMD) or die "close CMD failed: $!"; exit(1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Print STDOUT and STDERR to file and to screen
by Noame (Beadle) on Aug 03, 2009 at 07:15 UTC | |
by BioLion (Curate) on Aug 03, 2009 at 09:14 UTC |