2015-09-05 63 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