----- Original Message -----
From: "Shawn H Corey" <shawnhco...@gmail.com>
To: "Brandon McCaig" <bamcc...@gmail.com>
Cc: "John W. Krahn" <jwkr...@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 <jwkr...@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/


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


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to