Dru has asked for the wisdom of the Perl Monks concerning the following question:
but that isn't working for me. Could someone please explain what I'm doing wrong. Thanks.Though if you try to re-open "STDOUT" or "STDERR" as an "in memory" file, you have to close it first: close STDOUT; open STDOUT, '>', \$variable or die "Can't open STDOUT: $!";
use strict; use warnings; my $cmd = 'd:\clwhois.exe'; my $ip = '192.168.1.1'; my $file = 'd:\temp\output.txt'; open(STDOUT, ">$file") or die "Can't open $file: $!\n"; # redirect STD +OUT to a temp file system ("$cmd $ip") and warn "Can not execute $cmd: $!\n"; close STDOUT; open(STDOUT, "$file") or die "Can't open $file: $!\n"; while (<STDOUT>){ print; } close STDOUT;
|
|---|