in reply to Re^2: Ping host
in thread Ping host

Some notes:

Resulting in e.g. this example, which should also run on e.g. cygwin:

use strict; use warnings; my @hostnames = qw(www.leo.org dhbvg.xxx); foreach (@hostnames){ # my $a = `echo pinging $_ 1>&2 ; ping -c3 $_ 2>&1 | tee -a /dev/tt +y`; my $a = `ping -c3 $_ 2>&1`; if ($a =~ /unreach|unknown host/i){ print " For $_ : problems: $a."; } }
cu & HTH, Peter -- hints may be untested unless stated otherwise; use with caution & understanding.

Replies are listed 'Best First'.
Re^4: Ping host
by almut (Canon) on Oct 28, 2009 at 16:37 UTC
    I use 2>&1 to include output on stderr instead of just stdout

    Though this is generally a good idea, the native Windows ping (which is the only one known to me to ever output "Please check...") appears to write to stdout. I.e., this works fine for me:

    perl -le "print `ping badhost` =~ /please check/i ? 'bad':'good'"