[plug] Perl $? equivalent

Jay Turner jturner at bsis.com.au
Fri Mar 12 14:07:49 WST 2004


Thanks everyone..

I'm not yet up to Process Management in 'Learning Perl' but having skipped
ahead while waiting for a PLUG response. I have since discovered the
'system' command and have replaced my `cat..` call with system "cat"..

Having read this chapter now, I know understand why my initial idea of
$return=`cat mail | sendmail -t`;
print $return;

returned me an empty variable.

Thanks to all!

> -----Original Message-----
> From: Ryan [mailto:ryan at is.as.geeky.as]
> Sent: Friday, 12 March 2004 1:51 PM
> To: plug at plug.linux.org.au; jturner at bsis.com.au
> Subject: Re: [plug] Perl $? equivalent
>
>
> On Fri, 2004-03-12 at 13:41, Jay Turner wrote:
> > Hi All,
> >
> > Can anyone tell me what (if any) the Perl equivalent to Bash's '$?' is.
> >
> > I am calling a program (`cat mailFile | sendmail -t`) from a
> perl script and
> > I want to check that it has executed properly or not.
> >
> > In bash I would just "if [ $? -ne 0 ]" but I don't think I can locate an
> > equivalent in Perl.
>
> use system and read its return value:
>
> #!/usr/bin/perl
> use strict;
> my $return = system('cat','/etc/hosts');
> print "return: $return\n";
>
> =========
> the above returns 0, if you specify an unknown command it returns -1 and
> if the command runs and returns error, you get that error, for example
> if you cat a non existent file, you get 256.
>
> Ryan
>
>
>
>





More information about the plug mailing list