David wrote:
Thank you to all who helped me get a 6 digit date into perl. I certainly
heed warnings about not using outside system calls in perl however, I
have to make an outside call again.
#!/usr/bin/perl -w
use strict;
my $fileName = "081201 diskSpace.txt";
my $fileLoc = "/Users/mini/diskSpaceLog/$fileName";
system "(df -mg;) >$fileLoc &";
My problem is the last line. Output:
sh: -c: line 1: syntax error near unexpected token `diskSpace.txt'
sh: -c: line 1: `(df -mg;) >/Users/mini/diskSpaceLog/081201
diskSpace.txt &'
I made sure to follow the Learning Perl code. It's just not working for me.
Try it like this:
#!/usr/bin/perl
use warnings;
use strict;
my $fileName = '081201 diskSpace.txt';
my $fileLoc = "/Users/mini/diskSpaceLog/$fileName";
open my $PIPE, '-|', 'df', '-mg' or die "Cannot open pipe from 'df' $!";
open my $FH, '>', $fileLoc or die "Cannot open '$fileLoc' $!";
while ( <$PIPE> ) {
print $FH $_;
}
close $PIPE or warn $! ? "Error closing df pipe: $!"
: "Exit status $? from df";
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/