Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Syntax query

2 views
Skip to first unread message

Rajini Naidu

unread,
Apr 15, 2009, 9:20:01 AM4/15/09
to perl-t...@perl.org
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.
Is there any thing wrong in the syntax ????
 
-Rajini 
 
 

Simon Andrews

unread,
Apr 15, 2009, 9:35:24 AM4/15/09
to Rajini Naidu, perl-t...@perl.org

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....@bbsrc.ac.uk
+44 (0) 1223 496463

Brad Lhotsky

unread,
Apr 15, 2009, 9:38:20 AM4/15/09
to Rajini Naidu, perl-t...@perl.org
system() returns the exit code of the commands you executed. In this
case, your command was successful and thus your "zero" return.

http://tinyurl.com/chrdoo

If you're using Perl, you can do the processing that awk and grep are
doing as well.

--
Brad Lhotsky

0 new messages