簡體   English   中英

只有在通過java完成進程后,我的代碼才會繼續

[英]My code will continue only after process is finished via java

我正在通過一個進程運行exec命令。 我希望我的程序只在進程完成后才會繼續運行。 這是我的代碼:

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("tools/jadx/bin/jadx.bat -d JavaProjects/");

//the rest of the code
System.out.println("Process is finished");

我需要其余的代碼只在進程完成后執行,因為它取決於進程輸出。 有任何想法嗎?

我有答案,現在它有效!

Eevery流程具有輸入和輸出流。 我的具體過程必須清空他的輸入緩沖區才能繼續運行。 我添加的是以下代碼:

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("tools/jadx/bin/jadx.bat -d JavaProjects/");
out = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
    System.out.println(line);
}
int lExitCode = process.waitFor();
if (lExitCode == 0)
    System.out.println("\n\n$$$$$   Process was finished successfully   $$$$$\n\n");
else
    System.out.println("\n\n$$$$$   Process was finished not successfully   $$$$$\n\n");

waitFor就是為了這個目的:

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("tools/jadx/bin/jadx.bat -d JavaProjects/");
int lExitCode = process.waitFor();
//the rest of the code
if (lExitCode == 0)
  System.out.println("Process was finished successfull.");
else
  System.out.println("Process was finished not successfull.");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM