2017-07-18 121 views
0

我已创建名为“FileProcessor.jar”一个JAR文件,其包括:如果jar文件抛出异常,如何处理批处理文件中.jar文件的输出?

public class FileProcessor{ 
    public static void main(String[] args){ 
     try{ 
      // logic 
     }catch(Exception ex){ 
     // catch logic 
     } 
    } 
} 

我需要根据jar文件的输出来运行不同的逻辑。如果发生异常,我需要调用一个不同的jar文件。

+1

捕获异常并使用System.exit设置退出代码,然后在批处理中用'if errorlevel' – Marged

+0

@Marged更多的细节应该是一个答案,而不是一个评论。 –

回答

0

在此可以这样做最简单的形状:

try{ 
    // logic 
} 
catch(Exception ex){ 
    System.exit(1); 
} 
System.exit(0); 

在批办:

@echo off 
java -jar ... 
if errorlevel 1 goto runother 
if errorlevel 0 goto allok 
... 

请记住,if errorlevel有一个隐“大于或等于”。如果JVM崩溃,它会自行设置退出代码,您可以在这里阅读更多信息:Is there a complete List of JVM exit codes

相关问题