Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm fairly new to perl and I am trying to get some console output read into a variable within perl. Here is what I have so far:
$myVar = system ("C:\\configInfo.exe"); print "the Variable is:" . $myVar;

All I get for my output is: 'the Variable is: 0' Can someone please tell me what I'm doing wrong. Thanks.

Replies are listed 'Best First'.
Re: Reading console output into a perl
by duct_tape (Hermit) on Nov 25, 2003 at 21:57 UTC

    system returns the exit status of the program not the output. To retrieve the output of it, you can use backticks.

    $myVar = `C:\\configInfo.exe`; print "output: $myVar\n";
    Hope that helps.
    Brad

    update: double'd backslashes.. whoops. Thanks Corion.

      Awesome, Exactly what I needed to know, thanks.
Re: Reading console output into a perl
by vek (Prior) on Nov 26, 2003 at 13:53 UTC

    There's one other way of retrieving the output. Use open

    open (OUTPUT, "C:\\configInfo.exe |") || die "Couldn't run configInfo.exe - $!\n": while (<OUTPUT>) { # do stuff which each line of OUTPUT... }

    Note the pipe after the C:\\configInfo.exe command.

    -- vek --