This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Why is not the process terminating after executing the command Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Why is not the process terminating after executing the command" Watch "Why is not the process terminating after executing the command" New topic
Author

Why is not the process terminating after executing the command

Avi Nash
Ranch Hand

Joined: Jul 17, 2003
Posts: 69
Hi
The process is not getting terminated after executing a command.
Should not the process get terminated automatically once the command is executed? Or should we terminate it using a separate command.
The code:
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(commandToExecute);
process.waitFor();
System.out.println
("Exitvalue="+process.exitValue ());
is just waiting and not coming out.

rgds
Avinash
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

If the process sent any output to stdout or stderr, it may not terminate until you've read that data, even if you just discard it. Use the getErrorStream() and getInputStream() methods to get the streams.


[Jess in Action][AskingGoodQuestions]
Avi Nash
Ranch Hand

Joined: Jul 17, 2003
Posts: 69
Hi Ernest
Thanks a lot.
After reading the input stream, the process is getting terminated.
But I am not clear as to why should we read this data for the process to terminate.
thx again
rgds
Avinash
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Why is not the process terminating after executing the command
 
Similar Threads
handling Java child process execution
How to ensure a file is written completely.
Trouble in executing sqlldr through java
result of one statement is not avaialable to next statement ??
Runtime.exec problem