markjugg has asked for the wisdom of the Perl Monks concerning the following question:
This little failing test case illustrates my question:
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?# 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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: best practices for checking system return values for piped commands?
by Hue-Bond (Priest) on May 01, 2006 at 20:17 UTC | |
Re: best practices for checking system return values for piped commands?
by Anonymous Monk on May 02, 2006 at 01:35 UTC | |
by eXile (Priest) on May 02, 2006 at 02:41 UTC | |
by Anonymous Monk on Apr 08, 2009 at 07:33 UTC | |
Re: best practices for checking system return values for piped commands?
by billh (Pilgrim) on May 02, 2006 at 12:39 UTC | |
by markjugg (Curate) on May 04, 2006 at 15:27 UTC |
Back to
Seekers of Perl Wisdom