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

hi, i use system"ping x.x.x.x"; in win32 (only few lines), how can i get the output text then store into a output_variable (i means no output during the program until i print (use) the output_variable in the program) , thx a lot!

Replies are listed 'Best First'.
Re: deal with system output
by MZSanford (Curate) on Nov 29, 2001 at 21:35 UTC
    Sounds like a job for the mighty Backticks :

    my @output = `ping x.x.x.x`; ### do cool stuff with @output

    Or, better, use Net::Ping
    i had a memory leak once, and it ruined my favorite shirt.
(shockme) Re: deal with system output
by shockme (Chaplain) on Nov 29, 2001 at 21:43 UTC
    You can get the same effect of the backtick with qx:

    my @output = qx(ping x.x.x.x);

    If things get any worse, I'll have to ask you to stop helping me.

Re: deal with system output
by hotshot (Prior) on Nov 29, 2001 at 21:55 UTC
    just wanted to add that the system command you used, returens exit code and not the output as you wanted, so using what the brothers suggusted (backtics or qx) is what you wanted.

    Hotshot
Re: deal with system output
by mortis (Pilgrim) on Nov 30, 2001 at 01:45 UTC
    In addition to using the aforementioned backtick solutions, you may also want to look into IPC::Open2 and IPC::Open3, as they are much easier to use when the taint flag is on.

    It's usualy much easier (and safer) to just do:

    my $pid = open2($reader,$writer,'ping',@args);
    Instead of trying to un-taint the arguments to backticks.

    Kyle