Perl Programming Help:
simple ping script
Sep 26, 2012, 3:00 AM
Hi I am working on a simple cgi-script to print out ping results. It is a working script but with slight problem
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI qw(:standard);
use strict; # Check our syntax strictly
use diagnostics; # Tell us how to fix mistakes
use CGI; # Import the CGI module
print "Content-type: text/html\n\n";
open PING, 'ping -c 20 www.yahoo.com|' or die 'Failed';
--- This script prints the output only after the 20th ping. Is there a way I can print the result while the system is pinging real-time? This is because if the destination is not responding I would wait for sometime before I can find out that it is actually timing out. I would replicated this script as well for traceroute. Thanks in advance.
Sep 26, 2012, 7:13 AM
It would be better to use the Net::Ping module instead of the piped open.
Re: [ringo] simple ping script
To answer your question, you need to disable output buffering, which is done by setting the $| var to a true value. i.e.,