in reply to Re^3: Running a C program from Perl
in thread Running a C program from Perl

Hmmm,

I think it looks like I and to some extent you, are barking up the wrong tree (well on linux & AIX anyway) - consider the following behaviour exhibited by both Linux 2.6.28-11-generic and AIX 5.3:

user@unforgiven:~$ egrepa bash: egrepa: command not found user@unforgiven:~$ egrepa >/dev/null bash: egrepa: command not found user@unforgiven:~$ egrepa >/dev/null 2>&1 user@unforgiven:~$ perl -e '$res = `egrepa 2>&1`; print $res' user@unforgiven:~$
Personally, I would expect the one-liner to print bash: egrepa: command not found - as it does if entered from command line - but doesn't.

If, however, as you suggest, a valid command is used with invalid opts, then the re-direction works as expected and the error is seen (on both platforms).

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^5: Running a C program from Perl
by ikegami (Patriarch) on May 27, 2009 at 13:45 UTC

    Personally, I would expect the one-liner to print bash: egrepa: command not found - as it does if entered from command line - but doesn't.

    The shell was never invoked, so how can it display an error message? It's up to you to do your own error checking.

    $ perl -e'$res = `egrepa 2>&1`; print "$?:$!\n"; print $res' -1:No such file or directory (( Perl tried to execute egrepa, couldn't, and returned an error. Perl doesn't output error messages for you. )) $ perl -e'$res = `egrepa "" 2>&1`; print "$?:$!\n"; print $res' 32512: sh: egrepa: command not found (( Perl sees a shell command, and successfully executed the shell. The shell couldn't execute egrapa "", so it displayed and returned an error. ))