Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: IPC::System::Simple: Why isn't my exception caught?

by stefbv (Curate)
on Nov 20, 2013 at 13:56 UTC ( #1063529=note: print w/replies, xml ) Need Help??


in reply to IPC::System::Simple: Why isn't my exception caught?

There is no error because the exit value for "cat $file | wc -l" is 0 (zero).

Change the command to "wc -l file", as you say, and you get the error.

use IPC::System::Simple qw( capture $EXITVAL); use strict; use warnings; use Try::Tiny; my $file = 'foo'; my $result; try { $result = capture("cat $file | wc -l"); } catch { print "Error: $_"; }; print "Exitval is $EXITVAL";

Replies are listed 'Best First'.
Re^2: IPC::System::Simple: Why isn't my exception caught?
by karlgoethebier (Abbot) on Nov 20, 2013 at 14:45 UTC

    D'oh! I should have known this.

    But surprisingly:

    user@SVN:/svn/dumps> cat foo cat: foo: Datei oder Verzeichnis nicht gefunden user@SVN-Prod1:/svn/dumps> echo $? 1 user@SVN:/svn/dumps> cat foo | wc -l cat: foo: Datei oder Verzeichnis nicht gefunden 0

    I admit, that i didn't ask efficiently.

    What i actually want to do is:

    qx(/usr/local/csvn/bin/svnadmin -q dump $repos | /usr/bin/gzip > $dump);

    Respectively:

    capture("/usr/local/csvn/bin/svnadmin -q dump $repos | /usr/bin/gzip > $dump");

    And i wanted to know (and trap the exceptions) if any part of my piped command fails.

    Some time ago i saw an example on PM that managed this using system and IPC::IPC::Open3. I didn't find the example yet.

    Thank you very much and best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2021-10-26 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?