Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system() return 2

Status
Not open for further replies.

skosterow

Technical User
Feb 23, 2002
135
US
Okay pro a realy stupid question.... i looked through the perl stuff here and on activestate but cant seem to find what im looking for.

im trying to run a system command, via a web browser:

$command = "ping 127.0.0.1";
system($command);

then i want the return of this command (thinking it was $_ the default string for perl) to print on the screen. Actually more id like to minipulate $_.

Thanks for the wake up call ;-)
 
if you want what ping prints on the screen, try this

$a = `ping`;
print $a;


Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Mike,

No not to print the word PING but the return of the system command "PING" into a variable. The comand could be anything dcdiag, netdiag or ping.

thanks
 
Hi,

I think that the command that you want to use is:

$command = "ping 127.0.0.1";
system $command

this should work correctly!!!

Hope this helps!!

mark
 
hello Again,

Please ignore my last comments, its been a long day!!!

Why not try and do the ping from within the code rather than calling an external command, here is some example code that may be useful:

#!perl.exe


use Net::ping;
use Time::HiRes qw( gettimeofday tv_interval );

$bytes = 1024;
$timeout = 30;
$pingtype = "icmp";

$ping = Net::ping->new($pingtype , $timeout , $bytes);
while (true) {
if ($ping->ping($ARGV[0],5)) {
$t0 = [gettimeofday];
$elapsed = 1000 * tv_interval( $t0, [gettimeofday]);
print "Pinging $ARGV[0] with $bytes bytes of data rtt=$elapsed mSecs\n"
} else {
print "Host Could Not be Reached\n"
}
}

 
Greavemr,

Heres the deal I was using PING as an example, but say i wanted to use a command IE dcdiag, or netdiag... both of these have lengthy returns. (Didnt know if everyone would understand or know what these 2 commands are, there part of the win2k tool set) I need to parse the return of these 2 commands without saving them to a file then re-opening the file ;-)

thanks again! - scott
 
try MikeLacey's method.. using backticks (usually located on the tilde key on the upper left of the keyboard) will populate $a with the output from ping.exe
 
Mike - Chaz,

I am sorry thanks guys! I should have tried it instead of thinking that $a = `ping`; print $a would ONLY print ping!!

I guess my head was up my -

Thanks again fellas!

- Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top