Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

waiting for the end of the process

843798Sep 8 2003 — edited Sep 10 2003

I'm executing a command using the Runtime class and I have to wait until the end of the command to get the results. But, I don't want to sleep the thread for some undeterminated time. I'd like it just to wait until the command ends.

See in this code:

try
{
String result="";
Process p = Runtime.getRuntime().exec("sh"); //open a new shell

InputStream is = p.getInputStream();
OutputStream os = p.getOutputStream();
os.write("ifconfig -a | grep PROMISC -c\n".getBytes());
os.flush();

try {
Thread.currentThread().sleep(1000);
/*command should take some time to execute so wait for 10 secs .... I don't like this .... I would prefer waiting for the end the command ifconfig*/
}
catch (InterruptedException eIE) { }

while (is.available() > 0)
{
result = result + ( (char) is.read());
}
System.out.println(result);

}
catch (IOException e) {
System.out.println(e);
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2003
Added on Sep 8 2003
4 comments
240 views