Respected Monks,
I need to redirect the command output to a file in a Perl Script. So far, I have come across the following two ways to do it:
use warnings; use strict; open(PS,"ping localhost|") || die "Failed: $!\n"; while ( <PS> ) { #-- do something here }
Another method is:
use warnings; use strict; open (my $file, '>', 'output.txt') or die "Could not open file: $!"; my $output = `example.exe`; die "$!" if $?; print $file $output;
Please let me know which is the correct way to capture the output. I know there is more than one way to do what I am looking for, but which one of these two are correct in sort of a "Best Practice" way? Thwack me on the head if I am thinking too much and this is trivial :)
Perlpetually Indebted To PerlMonks
http://dwimperl.com/windows.html is a boon for Windows.use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
In reply to Correct way to capture command output to a file in Perl. by perl514
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |