`du -sk $dir1/$file1` produces error | Newbie | | Join Date: Sep 2008
Posts: 11
| |
Hi all,
I'm having a problem with the following piece of code in one of my programs: - @temp = split(/\s+/, `du –sk $dir1/$file1`);
-
push(@directorySizes, $temp[0]);
-
I'm getting the following error for each time the first line is called: "du: cannot access `\226sk': No such file or directory." Everything is working as it's supposed to, I'm getting the correct value for du -sk $dir1/$file1 but it still prints this error for some reason. I've tried running the same command manually from the command line and it turns out fine. Does anyone know why this error message keeps appearing, how do I make it go away?
KiSSa
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,571
| | | re: `du -sk $dir1/$file1` produces error
That would tell me that the "-" that precedes the options is not getting recognized. You might want to try escaping it with a "\".
Regards,
Jeff
| | Newbie | | Join Date: Sep 2008
Posts: 11
| | | re: `du -sk $dir1/$file1` produces error
Hi,
I tried doing: - @temp = split(/\s+/, `du \–sk $dir1/$file1`);
and it still acted the same way. Thanks for trying though.
KiSSa
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,091
| | | re: `du -sk $dir1/$file1` produces error
Try this and see if $out is populated: - $dir = "$dir1/$file1";
-
$out = `du -sk $dir`;
-
print $out;
| | Newbie | | Join Date: Sep 2008
Posts: 11
| | | re: `du -sk $dir1/$file1` produces error
I tried that and the $out populated as it was supposed to. Also tried inserting $dir instead of $dir1/$file1 in the split line but the error message still shows. This is so weird.
KiSS
|  | Expert | | Join Date: Jan 2007 Location: Southern California USA
Posts: 4,091
| | | re: `du -sk $dir1/$file1` produces error Quote:
Originally Posted by KiSSFRo I tried that and the $out populated as it was supposed to. Also tried inserting $dir instead of $dir1/$file1 in the split line but the error message still shows. This is so weird.
KiSS Well, I am not sure why that is but you can now split $out instead of trying to split the return data from the shell directly in the split() function. You could also try opening "du" with a pipe and split the data line by line if that is necessary.
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,571
| | | re: `du -sk $dir1/$file1` produces error
I tried your code on my local Linux machine and it works fine with no produced error. What OS are you working on?
I also produced the following, which does the same thing: -
my @temparray;
-
my @directorySizes
-
-
foreach my $line (`du -sk /home/jlk`){
-
@temparray=();
-
chomp($line);
-
@temparray = split(/\s+/, $line);
-
push(@directorySizes, $temparray[0]);
-
}
-
Either way, it seems to work fine. I was wrong about the \ earlier as the command is all inside of back tics, so it wouldn't matter. Just make sure that that character before the 'sk' is a dash. It doesn't show in the code tags for some reason.
Regards,
Jeff
|  | Expert | | Join Date: Sep 2008 Location: Sydney, Australia
Posts: 173
| | | re: `du -sk $dir1/$file1` produces error Quote:
Originally Posted by numberwhun Just make sure that that character before the 'sk' is a dash. It doesn't show in the code tags for some reason.
Regards,
Jeff
Sorry this isn't part of the topic but the - is coming up in *nix Character Encoding.
Guessing the code is set to windows character enc,
But for the topic - @temp = split(/\s+/, `du -sk $dir1/$file1`);
try this - @temp = split(/\s+/, "`du -sk $dir1/$file1`");
or - @temp = system(`du -sk $dir1/$file1`);
-
@temp1 = split(/\s+/, "@temp");
| | Newbie | | Join Date: Sep 2008
Posts: 11
| | | re: `du -sk $dir1/$file1` produces error Quote:
Originally Posted by Icecrack Sorry this isn't part of the topic but the - is coming up in *nix Character Encoding.
Guessing the code is set to windows character enc,
But for the topic - @temp = split(/\s+/, `du -sk $dir1/$file1`);
try this - @temp = split(/\s+/, "`du -sk $dir1/$file1`");
or - @temp = system(`du -sk $dir1/$file1`);
-
@temp1 = split(/\s+/, "@temp");
I tried both of those, still no dice. Thanks for trying to help though. This is driving me nuts, the program works, I just want those ugly errors to go away.
KiSS
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,571
| | | re: `du -sk $dir1/$file1` produces error Quote:
Originally Posted by KiSSFRo I tried both of those, still no dice. Thanks for trying to help though. This is driving me nuts, the program works, I just want those ugly errors to go away.
KiSS Again, specifically, what OS are you on? I have tried this several ways now, even similar to your original way and all work just fine.
Regards,
Jeff
| | Newbie | | Join Date: Sep 2008
Posts: 11
| | | re: `du -sk $dir1/$file1` produces error
Sorry forgot to answer your question Jeff. I'm using F-secure SSH Client to log onto a linux machine.
KiSS
|  | Site Moderator | | Join Date: May 2007 Location: New Hampshire
Posts: 2,571
| | | re: `du -sk $dir1/$file1` produces error Quote:
Originally Posted by KiSSFRo Sorry forgot to answer your question Jeff. I'm using F-secure SSH Client to log onto a linux machine.
KiSS Ok, Linux, that's a start. OS stands for Operating System. I ran the code on an Ubuntu 8.04 Hardy Heron machine and a Fedora Core 9 machine without issue.
Regards,
Jeff
|  | Expert | | Join Date: Sep 2008 Location: Sydney, Australia
Posts: 173
| | | re: `du -sk $dir1/$file1` produces error
try putting a reg ex to cancel perl Special characters,
example: - @temp = split(/\s+/, `du -sk $dir1/$file1`);
-
@temp =~ s/\\ /\\\ /g; #continue to cancel perl special char \ * ; ' " etc.
-
i have found that reading input can error on text that contains perl special char.
other than that i got nothing.
note: if you see something wrong above or a better method please post as this will teach me & others (thank you).
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|