Chas. Owens wrote:
On Wed, Apr 15, 2009 at 09:20, Rajini Naidu <rajinid...@gmail.com> 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";
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/