2015-09-05 60 views

回答

0

我不知道的autosys称道,但如果你可以执行使用Runtime,那么你需要看看命令的执行的输出。如果自动执行会在执行时返回一些内容,您将在错误发生时将其取出InputStreamErrorStream中的错误。

尝试这样:

public static void printStream(InputStream is, String type){ 
try 
    { 
     InputStreamReader isr = new InputStreamReader(is); 
     BufferedReader br = new BufferedReader(isr); 
     String line=null; 
     while ((line = br.readLine()) != null) 
      System.out.println(type + ">" + line);  
    } catch (IOException ioe){ 
      ioe.printStackTrace(); 
    } 
} 

public static void main(String args[]) 
{ 
    String cmd = "command to execute"; 
    Process proc = Runtime.getRuntime().exec(cmd); 
    printStream(proc.getInputStream(), "OUTPUT"); 
    printStream(proc.getErrorStream(), "ERROR"); 
} 
0

Process有一个方法exitValue()来获取子进程的退出值。 exitValue

例子:

Runtime rt = Runtime.getRuntime(); 
Process process = rt.exec("ls -al"); 
process.waitFor(); 
System.out.println(process.exitValue()); 
+0

请确保exitValue是特定的命令。检查你的程序哪个exitValue它将返回成功或错误。正常情况下,成功为0,错误为非零。但在ls命令的情况下,它将为0。 – Garry