Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
This little failing test case illustrates my question:
# Test error checking for piped system calls # We use 'boom', a non-existent command, for testing. use Test::More qw/no_plan/; use strict; ok_system_call("true"); ok_system_call("true|true"); not_ok_system_call("boom"); not_ok_system_call("boom|boom"); not_ok_system_call("true|boom"); not_ok_system_call("boom|true"); #################################3 sub ok_system_call { my $test = shift; my $expect_success = shift; $expect_success = 1 if not defined $expect_success; my $ok = (system($test) == 0); # my $exit_code = $? >> 8; # diag "exit code was: $exit_code"; return $expect_success ? ok($ok, $test) : ok(!$ok, $test); } sub not_ok_system_call { my $test= shift; return ok_system_call($test,0); }
The error checking doesn't work correctly on the last one ("boom|true"), so it fails. I believe this happens because although boom fails, something is sent through the pipe, and 'true' succeeds on the other end of the pipe. What's the best practicing for error checking a piped command so this case is covered?

In reply to best practices for checking system return values for piped commands? by markjugg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (6)
    As of 2015-07-07 02:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (86 votes), past polls