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

I have a problem I cannot seem to find the answer for...

In the snippet below, this is what is returned with the system command:

sql: started http: started eventd: started monitor: started scheduler: started server: started watchdog: started

and if I print out @status, that is exactly what shows up. However, when I try to split the string after the system command, I am getting nothing but zeros... Any ideas?
: : $command = "dfm service list"; @status = system($command); for ($x=0; $x<@status;$x++) { @sql_status = split /\s/, $status[$x]; }

Replies are listed 'Best First'.
Re: @status issues
by Fletch (Bishop) on Jul 03, 2007 at 15:15 UTC

    system returns the exit status of the command it ran, not it's output. You want backticks (see qx// in perlop).

Re: @status issues
by swampyankee (Parson) on Jul 03, 2007 at 15:17 UTC

    System returns the exit code from $command; it doesn't trap the command's output. To do that, you would use backticks or qx.

    emc

    Any New York City or Connecticut area jobs? I'm currently unemployed.

    There are some enterprises in which a careful disorderliness is the true method.

    —Herman Melville
Re: @status issues
by the_hawk_1 (Scribe) on Jul 03, 2007 at 16:31 UTC
    I've use something like
    open($file, $file_to_execute." |"); @text = <$file>; close $file;
    to catch the output of a system command.

    Well... I'm not sure this is the best way to acheive it, but it worked.

    - The_Hawk_1

Re: @status issues
by Moron (Curate) on Jul 04, 2007 at 13:23 UTC
    I agree with the diagnoses, but I tend to use IPC::Open3 or IPC::Run3 to write to and read back from spawned processes. Actually I only use Open3 because it's core; otherwise where that isn't an issue I'd just use IPC::Run3 more often instead.
    __________________________________________________________________________________

    ^M Free your mind!