Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Unanswered: 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;

  2. #2
    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.

  3. #3
    Join Date
    Apr 2007
    Posts
    2
    Thank you, KevinADC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •