?
Solved

Ping with Runtime

Posted on 2005-04-20
2
Medium Priority
?
446 Views
Last Modified: 2006-11-18
Why does this work Runtime.exec("ping www.yahoo.com"), but Runtime.exec("ping -n 1 www.yahoo.com") throws the attached exception?  If -n is a valid argument for ping on a windows platform?  I did verify that ping -n works from within DOS.

java.io.IOException: CreateProcess: "ping -n www.yahoo.com" error=2
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
        at java.lang.ProcessImpl.start(ProcessImpl.java:30)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
        at java.lang.Runtime.exec(Runtime.java:591)
        at java.lang.Runtime.exec(Runtime.java:464)
        at PingTest.PingTest(PingTest.java:19)
        at ThreadNetworkScan.ipCheck(ThreadNetworkScan.java:262)
        at ThreadNetworkScan.run(ThreadNetworkScan.java:24)
        at java.lang.Thread.run(Thread.java:595)

Thanks
0
Comment
Question by:jhughes4
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 13827628
Try

Runtime.exec(new String[] { "ping", "-n", "1", "www.yahoo.com" });
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13828001
:-)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question