Re: [cciug] Perl Help (a new problem)

From: Deer Hunter (ehz002@hotmail.com)
Date: Mon Jan 31 2000 - 19:43:23 EST


>From: "Brandon Metcalf" <bmetcalf@nortelnetworks.com>
>To: "Shanks, Jon" <jshanks@logicon.com>, "CCIUG (E-mail)"
><cciug@Rational.Com>
>Subject: Re: [cciug] Perl Help (a new problem)
>Date: Mon, 31 Jan 2000 14:32:03 -0800
>
>
>At 03:50 PM 1/28/00 -0800, Shanks, Jon wrote:
> >if (system($cmd) != "\"inspected\"") {
> > print STDERR "Accepted\n";
> > exit $ACCEPT;
> > }
> >else {
> > print STDERR "Rejected\n";
> > exit $REJECT;
> >}
> >My problem is that the system($cmd) call doesn't return the actual
>attribute
> >value. When I check that value I get 0 no matter if the attribute is set
>on
>
>$out = `cleartool blah blah ....`
>if ($out ne "inspected")
>

Unfortunatelly the back tick won't capture stderr from the cleartool
command. I don't a better way of capturing stderr in Perl but this one works
for me.

open(FH,"ct ... 2>&1|");
@out=<FH>;
close(FH);
if (grep(/<pattern>/,@out)) ...

In this way, you can do both error checking and condition checking.

BTW, since back tick is shell dependent, 2>&1 may not work in the back tick.
However it always works in open() statement.

>Note these are backticks. system() returns 0 on success and a nonzero
>value otherwise - it doesn't return the output of the command. Use
>backticks to capture the output. Also, != is for numeric comparison, ne is
>for string comparison.
>
>Brandon
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

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



This archive was generated by hypermail 2b29 : Sun May 06 2001 - 00:22:43 EDT