Results from a system call

Discussion in 'CGI/Perl/Python' started by rjulich, Feb 21, 2007.

  1. rjulich

    rjulich New Member

    Is it possible to put the results from a system call into a variable? I tried:

    $variable = system("fgrep date $file");
    print "VARIABLE: $variable\n";

    The results from the system call print to STDOUT, but when I print $variable, it prints:

    VARIABLE: 0

    I assume that the system call it returning 0 to mean that the command was successful, but is there a way to put the results from that system call into a variable?

    Thank you in advance.
    Ray
  2. mistwang

    mistwang LiteSpeed Staff

    I am not a perl programmer, probably cannot give your the correct answer. You should refer to a Perl programming book.
    In shell script I can use:

    variable=`fgrep date $file`

    to get result from the shell command, not sure about Perl though.
  3. rjulich

    rjulich New Member

    That worked. Thank you very much for the help. It's important to remember to use ` instead of '.

Share This Page