Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

backticks spits out error, but I want to handle errors! *shakes fist*

by dark314 (Sexton)
on Aug 16, 2006 at 23:23 UTC ( [id://567793]=perlquestion: print w/replies, xml ) Need Help??

dark314 has asked for the wisdom of the Perl Monks concerning the following question:

Update


I'm going to go with greenFox's response, because thats definately what I'm looking for, although the other responses were not wrong! thanks.

-----------------------Update Above-------------------------
I want to handle any errors that find comes accross, instead it spitting to standard out. Is there some way to do this? Im sure there is, here is my attempt which failed. Thanks!
foreach $spamuser (@users) { my $CUR_INBOX = "$MAIL_ROOT/$spamuser/cur"; @ham = `find $CUR_INBOX -type f` or warn "Error!\n"; }
  • Comment on backticks spits out error, but I want to handle errors! *shakes fist*
  • Download Code

Replies are listed 'Best First'.
Re: backticks spits out error, but I want to handle errors! *shakes fist*
by andyford (Curate) on Aug 16, 2006 at 23:43 UTC
    Well if you want real control, try File::Find module. It's been included with Perl for, well, somebody help me out here...
      i never wanna live without corelist again:
      $ corelist File::Find File::Find was first released with perl 5
Re: backticks spits out error, but I want to handle errors! *shakes fist*
by diotalevi (Canon) on Aug 16, 2006 at 23:45 UTC

    Use IPC::Open3.

    use IPC::Open3 'open3'; $SIG{CHLD} = 'IGNORE'; # see perlipc for the scoop open3( undef, my $ham_fh, my $ham_err_fh, 'find', $CUR_INBOX, '-type', 'f' ); <$ham_err_fh> or warn "Error!\n"; @ham = <$ham_fh>;

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: backticks spits out error, but I want to handle errors! *shakes fist*
by greenFox (Vicar) on Aug 17, 2006 at 03:26 UTC

    Check $? (perlvar). Something like:

    foreach $spamuser (@users) { my $CUR_INBOX = "$MAIL_ROOT/$spamuser/cur"; @ham = `find $CUR_INBOX -type f 2>&1`; $? and die "@ham $!"; }

    --
    Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Re: backticks spits out error, but I want to handle errors! *shakes fist*
by rodion (Chaplain) on Aug 16, 2006 at 23:28 UTC
    Try re-routing STDERR to STDOUT within the backtick command. You will then have to pick it out of the output. Another way is to pipe STDERR to a file, then look to see if the file is empty, and retrieve the contents of it if it isn't.
Re: backticks spits out error, but I want to handle errors! *shakes fist*
by Anonymous Monk on Aug 17, 2006 at 02:03 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://567793]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found