"Hubert Ian M. Tabug" wrote:
> 
> Hello,

Hello,

>         Has anyone ever tried toying or configuring fping
> and parsing its output via perl? The reason why I am asking
> this question is that, I am trying to capture the output
> generated by the command fping -s, what fping -s does is
> that it generates a summary output upon exit, I have tried
> to pipe, fping -s > testfile, or fping -s 1> testfile, but
> it just doesn't work. I am a beginner at perl, and I am
> wondering if there is a way perl can capture its output,
> fping -s after execution. I have tried $variable=`fping -s
> 202.8.xxx.xxx`, but the variable simply won't store fpings`s
> output. fping -s 1> myfile doesn't work either the output
> just generates after fpings' exit I think there is no way
> to capture the output of fping -s via pipe. Although any
> other fping option can be piped, i.e. fping -a, fping -u.
> I would greatly appreciate your help.


As the following demonstrates most of the output from fping -s
goes to STDERR and not STDOUT.

# fping -s 216.115.108.243                 
216.115.108.243 is alive

       1 targets
       1 alive
       0 unreachable
       0 unknown addresses

       0 timeouts (waiting for response)
       1 ICMP Echos sent
       1 ICMP Echo Replies received
       0 other ICMP received

 37.5 ms (min round trip time)
 37.5 ms (avg round trip time)
 37.5 ms (max round trip time)
        0.041 sec (elapsed real time)

# fping -s 216.115.108.243 > /dev/null

       1 targets
       1 alive
       0 unreachable
       0 unknown addresses

       0 timeouts (waiting for response)
       1 ICMP Echos sent
       1 ICMP Echo Replies received
       0 other ICMP received

 37.6 ms (min round trip time)
 37.6 ms (avg round trip time)
 37.6 ms (max round trip time)
        0.040 sec (elapsed real time)

# fping -s 216.115.108.243 2> /dev/null
216.115.108.243 is alive


Here is the relevant portion of the perlop manual page

perldoc perlop

[snip]
       qx/STRING/

       `STRING`
               A string which is (possibly) interpolated and then
               executed as a system command with `/bin/sh' or its
               equivalent.  Shell wildcards, pipes, and redirec�
               tions will be honored.  The collected standard
               output of the command is returned; standard error
               is unaffected.  In scalar context, it comes back
               as a single (potentially multi-line) string.  In
               list context, returns a list of lines (however
               you've defined lines with $/ or $INPUT_RECORD_SEP�
               ARATOR).

               Because backticks do not affect standard error,
               use shell file descriptor syntax (assuming the
               shell supports this) if you care to address this.
               To capture a command's STDERR and STDOUT together:

                   $output = `cmd 2>&1`;

               To capture a command's STDOUT but discard its
               STDERR:

                   $output = `cmd 2>/dev/null`;

               To capture a command's STDERR but discard its STD�
               OUT (ordering is important here):

                   $output = `cmd 2>&1 1>/dev/null`;

               To exchange a command's STDOUT and STDERR in order
               to capture the STDERR but leave its STDOUT to come
               out the old STDERR:

                   $output = `cmd 3>&1 1>&2 2>&3 3>&-`;

               To read both a command's STDOUT and its STDERR
               separately, it's easiest and safest to redirect
               them separately to files, and then read from those
               files when the program is done:

                   system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to