• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need to program for executing ping statement..

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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+.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had to do something similar recently and used

InetAddress ia = InetAddress.getByName(ipAddress);
return ia.isReachable(timeout*1000);
 
reply
    Bookmark Topic Watch Topic
  • New Topic