Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Checking and verifying a unix command sent in Perl

by razzz (Initiate)
on Jul 19, 2009 at 04:04 UTC ( #781410=perlquestion: print w/ replies, xml ) Need Help??
razzz has asked for the wisdom of the Perl Monks concerning the following question:

if I send an "echo $?" command in unix via perl e.g. using the System command, how can I check the output and verify it using perl? i.e. capture the command line output and check to make sure it is correct e.g. output is a 1 or a 0. Cheers, Razzz

Comment on Checking and verifying a unix command sent in Perl
Re: Checking and verifying a unix command sent in Perl
by jrsimmon (Hermit) on Jul 19, 2009 at 04:34 UTC
    The backtick operator `$command`; captures STDOUT from the $command issued. It does not capture STDERR (though you can tell the shell to send both STDOUT, if you want it). See perlop for the details.
Re: Checking and verifying a unix command sent in Perl
by friedo (Prior) on Jul 19, 2009 at 04:55 UTC
    If you need to capture both STDOUT and STDERR, a more robust option is to use IPC::Open3, which will give you separate filehandles for each.
Re: Checking and verifying a unix command sent in Perl
by ikegami (Pope) on Jul 19, 2009 at 05:47 UTC

    system already provides the child's exit code as its return value.

    $ true $ echo $? 0 $ perl -le'print system("true") >> 8' 0 $ false $ echo $? 1 $ perl -le'print system("false") >> 8' 1

    Echoing it and capturing it is a waste.

Re: Checking and verifying a unix command sent in Perl
by Bloodnok (Vicar) on Jul 19, 2009 at 15:23 UTC
    Hmm, is it just me, or does the OP bear the hallmarks of an XY question ??

    A user level that continues to overstate my experience :-))
Re: Checking and verifying a unix command sent in Perl
by leocharre (Priest) on Jul 20, 2009 at 13:18 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-07-31 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls