If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > execute unix command in perl script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-29-07, 13:02
seven7 seven7 is offline
Registered User
 
Join Date: Apr 2007
Posts: 2
execute unix command in perl script

hi
I am trying to execute the following unix command through perl script and put the result in array, but the output of the array is always 0. For exaple: if the output that I got from Unix is 'Hello Othello', the value which stored in $returncode is 0.

My code is:

my $returncode = system("grep $value /usr/share/lib/dict/words");
my @array1 = split/ /, $returncode;
Reply With Quote
  #2 (permalink)  
Old 04-30-07, 03:03
KevinADC KevinADC is offline
Registered User
 
Join Date: Feb 2006
Posts: 56
system() does not return output. It returns the exit status.

Use qx// or backtiks `` to capture output

my $returncode = qx|grep $value /usr/share/lib/dict/words|;

or you could just use perls grep function.
Reply With Quote
  #3 (permalink)  
Old 05-01-07, 08:57
seven7 seven7 is offline
Registered User
 
Join Date: Apr 2007
Posts: 2
Thank you, KevinADC
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On