You can periodically check if the process is still running using the code from this answer, and then post the message when the process is missing. On Windows 10, the process you're looking for is Calculator.exe
.
Here is a Java 8 way to check if the process is running:
private static boolean processIsRunning(String processName) throws IOException {
String taskList = System.getenv("windir") + "\\system32\\tasklist.exe";
InputStream is = Runtime.getRuntime().exec(taskList).getInputStream();
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
return br
.lines()
.anyMatch(line -> line.contains(processName));
}
}
And then you can wait for processIsRunning("Calculator.exe")
to be true.
Here's a quick and dirty implementation of that:
public static void main(String[] args) throws Exception {
Runtime.getRuntime().exec("calc.exe").waitFor();
while (processIsRunning("Calculator.exe")) {
Thread.sleep(1000); // make this smaller if you want
}
System.out.println("Program has been closed successfully");
}