in reply to Executing independent commands in PERL

Perhaps   ping -t perlmonks.org > ping.log   isn't working because the -t option goes forever until you stop it. So the the file ping.log is never closed. (You might take a look at the -n option.)

You don't make clear if you *need* a log file or if that is just your strategy for accomplishing your analysis.

If you are open to other ways of grabbing the data, you might skip redirecting the results to a file. Consider using back-ticks or qx(...) and then just wait for each run before proceeding. Here's a brief example with a generous sprinkling of intermediate variables for clarity.

#!/usr/bin/perl5 -w use strict; my ($avg_time, $raw_data, @times, $time_count, $total_time); my $repeats = 5; my $addr = 'www.perlmonks.net'; for (my $i = 1; $i <= $repeats; $i++) { $raw_data = `ping $addr`; # NOTE back-ticks # Now do something interesting. We'll just... @times = $raw_data =~ /time=(\d+)/g; $total_time = 0; $time_count = 0; for (@times) { $total_time += $_; $time_count++; } $avg_time = $total_time / $time_count; print "$i. Average time: ${avg_time}ms\n"; }
Which produces:
1. Average time: 61.25ms 2. Average time: 61.75ms 3. Average time: 60.75ms 4. Average time: 62ms 5. Average time: 62.25ms
You could, of course, just collect your data in the larger for loop and then do your analysis on the whole thing after you have collected as many ping responses as you need. Just make sure you don't set the data gathering processes to run forever.   ;-)

Replies are listed 'Best First'.
Re: Re: Executing independet commands in PERL
by FiReWaLL (Scribe) on Mar 08, 2001 at 13:05 UTC

    It solves the ping problem, but doesn't solve "executing another program WITHOUT stoping mine".

    This ping thing came into my mind, because where I'm living now I have a BAD ISDN connection that needs to be controlled, so I started opening a window and ping perlmonks -t and just look at it.

    After, as a good programmer, I saw so many data passing in the screen and the only thing that I could think about was "ANALYSE!!!!!", so I changed the ping -t into a log file, and started to make a little program that got a little bit bigger, and bigger, and finally, I wanted to put all toghether, and then... the rest you know...

    So my main question is not how to ping and log, or how to ping and analyse, is how to execute something else without worying about it after started...

    I got a lot of answers that worked below like as for example system "open ping -t perlmonks.org >ping.log".

    That one worked perfeclty for what I needed, like that I can open a text editor, I can open a Browser, and in windows, I can say the file that I want to open, or the site (in the case of the browser)...


    -------
    []'s
    FiReWaLL
    The only thing you regret in life, is the risk you don't take.