On 15 Apr 2009, at 14:20, Rajini Naidu wrote:
Hi,
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.
I think you're misunderstanding what the system function does. This
will run the command you specify but doesn't allow you to capture the
output from the command. System returns the exit status of the
command you ran, and an exit status of 0 would mean that the command
completed successfully.
If you want to capture the output from the command then you probably
want to use backticks:
my $test2 = `/usr/atria/bin/cleartool desc \$include | grep created |
awk -F\" \" \'{print \$2}\' | cut -b 1-9`;
This will take the output from the command and assign it to $test2.
Hope this helps
Simon.
--
Simon Andrews PhD
Babraham Bioinformatics
www.bioinformatics.bbsrc.ac.uk
simon.andr...@bbsrc.ac.uk
+44 (0) 1223 496463