CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
simple ping script


New User

Sep 26, 2012, 3:00 AM

Post #1 of 2 (2047 views)
simple ping script Can't Post

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|' or die 'Failed';
while(<PING>) {
print "$_<br>";
close (PING);

--- 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.

Veteran / Moderator

Sep 26, 2012, 7:13 AM

Post #2 of 2 (2041 views)
Re: [ringo] simple ping script [In reply to] Can't Post

It would be better to use the Net::Ping module instead of the piped open.

To answer your question, you need to disable output buffering, which is done by setting the $| var to a true value. i.e.,

$| = 1;


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives