2013-10-03 33 views
-1

我不得不執行程序RegAlloc.jav一個與輸入重定向(4.miniIR文件)執行在子目錄程序時,在Java exec命令無法正常工作

try{ 
    String s="java -classpath MiniRA/ RegAlloc < MiniRA/4.miniIR"; 
    Process pro2 = Runtime.getRuntime().exec(s); 
    BufferedReader in =new BufferedReader(new InputStreamReader(pro2.getInputStream())); 
    String line = null; 
    while ((line = in.readLine()) != null) { 
     text+=line; 
     text+="\n"; 
     System.out.println(text); 
    } 
    System.out.println(text); 
    } 
catch(IOException e) { 
    System.out.println("not Okey"); 
} 

,但我沒有得到正確的結果;輸出窗口剛剛顯示,不會終止程序。任何人都可以幫我找到錯誤嗎?

+0

請問你的新問題,從[一個你問40分鐘前]不同(http://stackoverflow.com/questions/19158586/redirection-in-exec-method-in-java) ? –

+2

[他們](http://stackoverflow.com/questions/19116465/how-to-execute-a-java-program-using-another-java-program-stored-in-a-sub-directo)[是] (http://stackoverflow.com/questions/19134496/how-to-run-a-java-program-stored-in-sub-directory-from-another-java-program-in-t)[everywhere](http ://stackoverflow.com/questions/19158586/redirection-in-exec-method-in-java)! –

+0

@ n.st這就解釋了'它對我來說是迫切的。:(' – devnull

回答

0

如果只是關於進程沒有終止,您可以強制在代碼中使用pro2.destroy()來終止它,在try塊結束時。

0

您必須在您的過程中從stdin讀取。但是你可以嘗試掛鉤stdin的外部過程。嘗試更換:

BufferedReader in =new BufferedReader(new InputStreamReader(System.in));