This is because you send ls's output to a pipe, and the command on the
right of the pipe get executed successfully.
Try this test on shell:

-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.

On Thu, Mar 27, 2008 at 6:50 PM,  <[EMAIL PROTECTED]> wrote:
> I am really going crazy here. I have the following system call that I
>  would like to run from perl:
>   "ls *.txt | xargs cat > out"
>  if *.txt does not exist then I expect to get an exit code different
>  from 0.
>
>  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.
>
>
>
>  --
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>  http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to