develooper Front page | perl.beginners | Postings from April 2010

Re: special variable $? usage : SOLVED

From:
Bruno Costacurta
Date:
April 26, 2010 04:45
Subject:
Re: special variable $? usage : SOLVED
Message ID:
20100426134519.303556n2cw2tfrb4@webmail.costacurta.org

----- Original Message -----
From: "Shawn H Corey" <shawnhcorey@gmail.com>
To: "Brandon McCaig" <bamccaig@gmail.com>
Cc: "John W. Krahn" <jwkrahn@shaw.ca>; "Perl Beginners" <beginners@perl.org>
Sent: Saturday, April 24, 2010 7:41 PM
Subject: Re: special variable $? usage


> Brandon McCaig wrote:
>> On Thu, Apr 22, 2010 at 1:05 PM, John W. Krahn <jwkrahn@shaw.ca> wrote:
>>> What does that sentence mean?  What would the number returned from  
>>> the shell
>>> (bash, csh, ksh, etc.) have to do with the numbers output from "runmqsc
>>> SQFR"?
>>
>> Perhaps he really wants to read and parse the output from the
>> command(s) instead of checking the status?
>>
>> my $cmdline = "echo 'DIS CHS(*)' | runmqsc SQFR | grep CHANNEL | sort
>> | uniq -c";
>>
>> # Open input pipe from command line.
>> open(my $pipe, "-|", $cmdline);
>
> open my $pipe, '-|', $cmdline or die "could not open pipe: $!\n";
>
>>
>> for my $line (<$pipe>)
>
> while( my $line = <$pipe> )
>
>> {
>>     # Parse columns from $line here.
>>     # For example, let's just print them.
>>     print $line;
>> }
>>
>> close($pipe);
>
> close $pipe or die "could not close pipe: $!\n";
>
>>
>> __END__
>>
>> This is similar to piping the command to your program and reading  
>> from STDIN.
>>
>> # Shell command.
>> $ echo foo | your_program
>>
>> You can learn about the various modes of the open function with
>> `perldoc -f open'. Look for the MODE argument in relation to command
>> pipes.
>>
....

You're all right : indeed parsing the output (instead the checking of  
the return via $?) is the correct solution using solution introduced  
previously.

( Sorry to be confusein my initial question. I started the problem  
from the side as using the special variable $? as a return of a system  
command. )

Many thanks for help.
Bye,
Bruno

-- 
Linux Counter #353844
http://counter.li.org/


----------------------------------------------------------------




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About