0
//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.

MikaelF
  • 3,157
  • 3
  • 21
  • 33
b-rad15
  • 55
  • 1
  • 2
  • 12

1 Answers1

0

Nevermind just realised i was writing the wrong program to the wrong variable and was keeping that program the same (it was not running) and changing the other variable to programs that were running so it was returning false because the program was indeed not running

b-rad15
  • 55
  • 1
  • 2
  • 12