• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to program for executing ping statement..  RSS feed

 
sridhar Ranganathan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need the program for to execute the ping...I used like this Iam not getting the output in console.....

<CODE>
try{
Process p = null;
Runtime run = Runtime.getRuntime();
p = run.exec("ping 168.94.112.203");
}catch(Exception e)
{
}</CODE>

I have loop of ip address,each time
I need to find out whether the system is working /not...Can any one help me please the same.
Thanks & Regards,
Sridhar.R
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output won't be written to the console. It's written to the output stream of the process. You can get this using the Process.getOutputStream method. You can then read the response from this stream and do with it whatever you want.
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never use Runtime.getRuntime().execute() without reading the classic article by Michael Daconta; do a google search for "when Runtime.exec() won't".
Also find out about the ProcessBuilder class in Java 5+.
 
dee anderson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to do something similar recently and used

InetAddress ia = InetAddress.getByName(ipAddress);
return ia.isReachable(timeout*1000);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!