On 27 мар, 03:50, [EMAIL PROTECTED] (Ultra Star X) 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 ?
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/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/