簡體   English   中英

執行命令行應用程序

[英]Executing command line app

我正在嘗試從代碼對類文件執行 JAD 反編譯器:

Process p = Runtime.getRuntime().exec("c:\\1\\jad.exe c:\\1\\EIn.class");
//All paths are correct, "c:\\1\\jad.exe c:\\1\\EIn.class" wotks when I run it in cmd

當我調試時,我沒有收到任何錯誤,調試器移動到下一行...

如果我把:

int res = p.waitFor(); 

它只是掛起。

更新:

BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String str = null;
while ((str = in.readLine()) != null) { //Stucks here
}

jad反編譯器是否正在等待您通過 stdin 輸入?

要查看您收到的錯誤,請使用getOutputStreamgetErrorStream以查看反編譯器正在寫出的內容。

您可以使用ProcessBuilder類使重定向流更加愉快。

public static void main(String[] args) throws Exception {

    String[] cmd = { "c:\\1\\jad.exe", "-c:\\1\\EIn.class" };
    Process p = Runtime.getRuntime().exec(cmd);
    p.waitFor();
}

這是 Java 中的陷阱,請看一下這個頁面,你會得到比你想要的更多!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM