Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

how to capture bash errors like 'command not found' from Perl backticks

104 views
Skip to first unread message

Isaac Ho

unread,
Nov 7, 2011, 2:53:05 PM11/7/11
to
Hi, I've read the perlfaq on capturing stderr from an external
command. However, I cannot seem to get it to capture ALL error
messages. In particular, if the command I'm trying to run externally
fails due to 'command not found' at the shell level, I cannot capture
it with the methods listed.

For instance:

use strict;
use IPC::Open3;
use Symbol qw(gensym);

my $cmd="bogus";
my $pid=open3(gensym, ">&STDERR", \*PH, $cmd );
while( <PH> ) { print $_ }
waitpid( $pid, 0 );

This runs the command "bogus", which fails when I run it by hand as:

-bash: bogus: command not found


however, running the above wrapper perl script gives:

open3: exec of bogus failed at test.pl line 7

which is too generic of a message to be useful for me.

When I run:

bogus 2> temp.err
cat temp.err

Then it does capture the stderr but I'd like to not have to write temp
files like this, since I am running commands in a pipeline context...

Thanks,

Isaac


Message has been deleted
0 new messages