ProcessDemo: Added exception handling (nicer)
This commit is contained in:
@@ -6,8 +6,19 @@ public class ProcessDemo {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\HeidiSQL\\heidisql.exe");
|
ProcessBuilder builder = new ProcessBuilder("C:\\Program Files\\HeidiSQL\\heidisql.exe");
|
||||||
try {
|
try {
|
||||||
|
// Start the process
|
||||||
Process process = builder.start();
|
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
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user