I have the following code:
Process p = Runtime.getRuntime().exec(args);
and I want my program to wait for Runtime.getRuntime (). exec (args); to finish work in the last 2-3 seconds, and then continue.
Ideas?
Here is a sample 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 on this site: http://docs.rinet.ru/JWP/ch14.htm
use Process.waitFor () :
Process p = Runtime.getRuntime().exec(args); int status = p.waitFor();
From JavaDoc:
, , , , , . , . , .
Source: https://habr.com/ru/post/1739442/More articles:Log4j configuration: ConsoleAppender for System.err? - consoleProperly use Marshal.Copy - c #How does IProgressMonitor pause? - javaС# оболочка для массива из трех указателей - arraysfatal error LNK1112: module type of module "X86" conflicts with type of target machine "AMD64" - visual-c ++FPDF in PHP, setX just inserts the first line - phpjQuery removing elements from DOM still showing reporting - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1739445/do-the-changes-to-cpumask-using-schedsetaffinity-take-place-immediately&usg=ALkJrhjP-9bqhHbBVKlc5V8vX6nQAdph_QHibernate naturalID - hibernateIE innerHTML прерывает предложение, если последнее слово содержит '&' (амперсанд) - javascriptAll Articles