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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
simple ping script

 



ringo
New User

Sep 26, 2012, 3:00 AM

Post #1 of 2 (1232 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


#!/usr/bin/perl

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


FishMonger
Veteran / Moderator

Sep 26, 2012, 7:13 AM

Post #2 of 2 (1226 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.
http://search.cpan.org/~smpeters/Net-Ping-2.36/lib/Net/Ping.pm

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

Code
$| = 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