So to test I do:
use strict;
my $f = "file_which_does_not_exist";
# method 1
print "test 1\n";
qx(ls $f | xargs cat);
print $?,"\n";
#method 2
print "test 2\n";
system("ls $f | xargs cat");
print $?,"\n";
Both calls return 0 instead of returning error as 'ls' fails.
Help. How do I do this ?
Would 'open' help ?
C.
-bash-3.00$ ls tttt|xargs cat
ls: tttt: No such file or directory
-bash-3.00$ echo $?
0
-bash-3.00$ ls tttt
ls: tttt: No such file or directory
-bash-3.00$ echo $?
1
As you see, the first command always returns a 0.
> --
> To unsubscribe, e-mail: beginners-...@perl.org
> For additional commands, e-mail: beginne...@perl.org
> http://learn.perl.org/
>
>
>
So Jeff already explained why. Now what can be done.
One way: if you still want to run this command line correctly, try
IPC::Run. It is a bit tricky to use first, but can safely run any
pipelines.
Another way: try using native Perl methods. opendir() and readdir()
instead of ls, match file names with regex, and then read and append
files, or run cat.
/sandy
http://myperlquiz.com/
C.