Ivan Novick wrote:
> 
> Hi,

Hello,

> does anyone know syntax to run a command and redirect its output directly to
> a file?
> 
> Equivalent to myCommand > myFile in shell

open my $pipe, 'myCommand |' or die "Cannot open pipe from myCommand:
$!";
open my $fh, '>', 'myFile' or die "Cannot open myFile: $!";
print $fh while <$pipe>;
close $pipe or die "Cannot close pipe from myCommand: $!";


Or if myCommand outputs "binary" data.

open my $pipe, 'myCommand |' or die "Cannot open pipe from myCommand:
$!";
binmode $pipe;
open my $fh, '>', 'myFile' or die "Cannot open myFile: $!";
binmode $fh;
print $fh while read $pipe, $_, 1024;
close $pipe or die "Cannot close pipe from myCommand: $!";



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to