我需要在else
中捕获或打印错误。
下面是我的代码:
private static void runProcess(String command) throws Exception {
Process pro = Runtime.getRuntime().exec(command);
printLines(command + " stdout:", pro.getInputStream()); // For RUN output only
pro.waitFor();
if (pro.exitValue() == 0)
{
System.out.println("Status: COMPILATION SUCCESSFULL!!");
// sendFile(); // to code checker
sendFile();
System.out.println("File Sent!");
} else
System.out.println("Syntax Error Found!");
}
答案 0 :(得分:0)
也许是这样吗?
private static void runProcess(String command) throws Exception {
try{
Process pro = Runtime.getRuntime().exec(command);
printLines(command + " stdout:", pro.getInputStream()); // For RUN output only
pro.waitFor();
if (pro.exitValue() == 0) {
System.out.println("Status: COMPILATION SUCCESSFULL!!");
// sendFile(); // to code checker
sendFile();
System.out.println("File Sent!");
}
}catch(Exception e){
//Your exception message here, handle it as you want
System.out.println(e.getMessage());
System.out.println("Syntax Error Found!");
}
}