Capturing command output in Perl 
Author Message
 Capturing command output in Perl

[posted and sent via email]

Use backticks instead.

$response = `ping $host`;

will store the response of ping in the variable $response.

Quote:

> I am writing a perl script in NT which runs the PING.EXE command to check a
> node (using system() or win32::create() ??) and examine the reply of
> PING.EXE to see whether the node is alive or dead. My question is how can I
> capture the output of PING.EXE in perl script to carry out the processing ?

> wkchiu.

--
-------------------------------------------------------------
Andrew J. Perrin - NT/Unix/Access Consulting -  (650)938-4740

      http://www.*-*-*.com/
-------------------------------------------------------------


Sun, 25 Mar 2001 03:00:00 GMT  
 Capturing command output in Perl
: I am writing a perl script in NT which runs the PING.EXE command to check a
: node (using system() or win32::create() ??) and examine the reply of
: PING.EXE to see whether the node is alive or dead. My question is how can I
: capture the output of PING.EXE in perl script to carry out the processing ?

: wkchiu.

Just run ping.exe in pipe.

Something like this ...

open(PIPE,"ping.exe host|") or die("\n Can't open pipe !\n");
while(<PIPE>) {
        print("$_"); # This is output do what ever you want

Quote:
}

close(PIPE);

t.pena



Sun, 25 Mar 2001 03:00:00 GMT  
 Capturing command output in Perl
Hi all,

 When trying to pipe the output of a command into a
Perl script in WIN32, I can get the command, like dos
"Dir", to execute but the output never appears on $_ .
  Is it first necessary to make a registry entry like:
HKEY_LOCAL_MACHINE\Software\ActiveWare\Perl5\COMSPEC
or is something else wrong?
  This is a powerfull feature of Perl . Maybe there is a step
in the install of Perl 5 that I missed?
  Has anyone else successfully piped commands into
scripts in the WIN32 port of Perl?
    Thanks to all who respond,
                Mark



Quote:

> : I am writing a perl script in NT which runs the PING.EXE command to
check a
> : node (using system() or win32::create() ??) and examine the reply of
> : PING.EXE to see whether the node is alive or dead. My question is how
can I
> : capture the output of PING.EXE in perl script to carry out the
processing ?

> : wkchiu.

> Just run ping.exe in pipe.

> Something like this ...

> open(PIPE,"ping.exe host|") or die("\n Can't open pipe !\n");
> while(<PIPE>) {
>    print("$_"); # This is output do what ever you want
> }
> close(PIPE);

> t.pena



Sun, 25 Mar 2001 03:00:00 GMT  
 Capturing command output in Perl

Quote:

> I am writing a perl script in NT which runs the PING.EXE command to check a
> node (using system() or win32::create() ??) and examine the reply of
> PING.EXE to see whether the node is alive or dead. My question is how can I
> capture the output of PING.EXE in perl script to carry out the processing ?

perldoc -f open

--
-o- Brad Murray                  "Most programs aren't released;
-o- Alcatel Canada                they are allowed to escape."
-o- Software Analyst                        Jeff DelPapa



Sun, 25 Mar 2001 03:00:00 GMT  
 Capturing command output in Perl
Use
  $output = `ping.exe .....`;

PS: Do not use Single quotes instead use back quote...

-- Baliga

Quote:

> I am writing a perl script in NT which runs the PING.EXE command to check a
> node (using system() or win32::create() ??) and examine the reply of
> PING.EXE to see whether the node is alive or dead. My question is how can I
> capture the output of PING.EXE in perl script to carry out the processing ?

> wkchiu.



Sun, 25 Mar 2001 03:00:00 GMT  
 Capturing command output in Perl
I am writing a perl script in NT which runs the PING.EXE command to check a
node (using system() or win32::create() ??) and examine the reply of
PING.EXE to see whether the node is alive or dead. My question is how can I
capture the output of PING.EXE in perl script to carry out the processing ?

wkchiu.



Mon, 26 Mar 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. capturing command line error or output from `<command>`

2. Capturing System Command Output with Perl on Windows/Apache

3. capturing output of FILEHANDLE "| command"

4. capturing output from a remote command (how?)

5. capturing output of executed system command

6. capturing output of piped commands

7. Help with Piped command, capturing output

8. Capture command output into list?

9. Capturing output of a system command

10. help with capturing output of open command

11. How do I capture output from a print command

12. Capturing Command Line Output

 

 
Powered by phpBB® Forum Software