ProcessDemo: Added exception handling (nicer)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user