How to synchronize java code
•
Java
I have the next code:
Process p = Runtime.getRuntime().exec(args);
I want my program to wait for the runtime getRuntime(). exec(args); Completion causes it to last 2-3 seconds before continuing
Ideas?
Solution
This is an example code:
Process proc = Runtime.getRuntime().exec(ANonJava.exe@);
InputStream in = proc.getInputStream();
byte buff[] = new byte[1024];
int cbRead;
try {
while ((cbRead = in.read(buff)) != -1) {
// Use the output of the process...
}
} catch (IOException e) {
// Insert code to handle exceptions that occur
// when reading the process output
}
// No more output was available from the process,so...
// Ensure that the process completes
try {
proc.waitFor();
} catch (InterruptedException) {
// Handle exception that Could occur when waiting
// for a spawned process to terminate
}
// Then examine the process exit code
if (proc.exitValue() == 1) {
// Use the exit value...
}
You can find more information on this site: http://docs.rinet.ru/JWP/ch14.htm
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
