ProcessDemo: Added exception handling (nicer)

This commit is contained in:
2024-02-23 08:18:45 +01:00
parent 2cdc062fc2
commit 8f9cd50556

View File

@@ -6,8 +6,19 @@ public class ProcessDemo {
public static void main(String[] args) {
ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\HeidiSQL\\heidisql.exe");
try {
// Start the process
Process process = builder.start();
} catch (IOException e) {
// Wait for the process to terminate
int exitCode = process.waitFor();
// Check if the process terminated successfully
if (exitCode == 0) {
System.out.println("Process executed successfully!");
} else {
System.out.println("Process failed with error code: " + exitCode);
}
} catch (InterruptedException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}