develooper Front page | perl.beginners | Postings from March 2008

system calls return code

Thread Next
From:
ultra.star.x
Date:
March 27, 2008 05:06
Subject:
system calls return code
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.



Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About