//Credit to this post as much of the code was sourced from it http://stackoverflow.com/a/37629840
public class ApplicationUtilities {
// http://stackoverflow.com/a/19005828/3764804
private static boolean isProcessRunning(String processName) throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder("tasklist.exe");
Process process = processBuilder.start();
String tasksList = toString(process.getInputStream());
return tasksList.contains(processName);
}
// http://stackoverflow.com/a/5445161/3764804
private static String toString(InputStream inputStream) {
Scanner scanner = new Scanner(inputStream, "UTF-8").useDelimiter("\\A");
String string = scanner.hasNext() ? scanner.next() : "";
scanner.close();
return string;
}
}
这段代码昨晚为我工作但是现在当我尝试添加do while循环时,isProcessRunning
代码只会返回值false。
有没有什么我在我的方面做错了,因为这些特定的程序在我在程序的另一部分添加了do while循环之前为它运行返回了一个真值。
答案 0 :(得分:0)
没关系,只是意识到我正在将错误的程序写入错误的变量并保持该程序相同(它没有运行)并将其他变量更改为正在运行的程序,因此它返回false因为程序确实不是运行