//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;
}
}
This code was working for me last night however now while I was trying to add the do while loop the isProcessRunning
piece of code will only return the value false.
Is there something I am doing wrong on my end as these specific programs were returning a true value for it running before I added a do while loop in another portion of the program.