Re: Syntax query
- From: chas.owens@xxxxxxxxx (Chas. Owens)
- Date: Wed, 15 Apr 2009 10:49:31 -0400
On Wed, Apr 15, 2009 at 10:41, John W. Krahn <jwkrahn@xxxxxxx> wrote:
Chas. Owens wrote:snip
On Wed, Apr 15, 2009 at 09:20, Rajini Naidu <rajinidots@xxxxxxxxx> wrote:
I am trying to execute the below line in the perl program and returns a
value 0.
my $test2 = "";
my $include = "file";
$test2 = system("/usr/atria/bin/cleartool desc \$include | grep created |
awk -F\" \" \'{print \$2}\' | cut -b 1-9 ");
The value returned by $test2 is 0. I suspect grep and awk commands are
not
getting executed.
Is there any thing wrong in the syntax ????
The system[1] function returns 0 on success and a nonzero value
specific to the operating system on failure (often the programs
exit code and the value returned by exec[2]). You could use the
qx// operator[3] to capture the STDOUT of the command:
my $test2 = qx{/usr/atria/bin/cleartool desc \$include |
grep created | awk -F\" \" \'{print \$2}\' | cut -b 1-9};
but a much safer and faster way is to use the open[4] function
and avoid using external programs like grep and awk:
open my $pipe, "-|", "/usr/atria/bin/cleartool", "desc", $include
or die "could not run cleartool: $!";
my @matches;
while (<$pipe>) {
next unless /created/;
my @rec = split;
push @matches, substr $rec[1], 0, 9;
}
Don't forget to verify that the pipe also closed correctly:
close OUTPUT or warn $! ? "Error closing /usr/atria/bin/cleartool pipe: $!"
: "Exit status $? from /usr/atria/bin/cleartool";
If that is going to match the example it should be
close $pipe
or warn $! ? "Error closing /usr/atria/bin/cleartool pipe: $!"
: "Exit status $? from /usr/atria/bin/cleartool";
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
.
- References:
- Syntax query
- From: Rajini Naidu
- Re: Syntax query
- From: Chas. Owens
- Re: Syntax query
- From: "John W. Krahn"
- Syntax query
- Prev by Date: Re: Syntax query
- Next by Date: stdin vs file
- Previous by thread: Re: Syntax query
- Next by thread: Re: Syntax query
- Index(es):
Relevant Pages
|