On 9/7/05, Frank Geueke, III <[EMAIL PROTECTED]> wrote: > Hi Everyone. I've been reading the list for the past > few days now and I have something maybe worth asking. > What I am wondering about at the moment is how to get > a possible error message from a command that is run in > the shell. i.e. > > my $cmd = "sudo -u userlogin " . > "/usr/bin/ssh -l $cnrip_user ${$ip_ref}[0] " . > "'/opt/nwreg2/usrbin/nrcmd -r -N $cnr_user " . > "-P $cnr_pass client list '"; > @results = `$cmd`; > > So it's basically a big clunky command and I know I > should probably split it into individual ones with > their own error handling... But for now I'd like to > be able to grab an error if possible. The error I'm > getting is from ssh not having the proper keys for a > host. There's about half a screen worth of stuff > displayed with it. (This is what I see when I do the > commands manually from the shell.) Any ideas? > > Regards. > ~Frank > >
The easiest thing would be to redirect the command's STDERR to a temporary file and check the flie: my @results = `$cmd 2> $tempfile`; if ( -s $tempfile) { #do something; } or something to that effect. If you need more sophisticated redirection, see IPC::Open3 and the section "How can I capture STDERR from an external command?" in perlfaq8 HTH, --jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!