Tag: runtime.exec

从Java程序编译C代码

我正在尝试以下代码来编译带有Java程序的外部C程序 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public static void main(String[] args){ try{ Runtime rt=Runtime.getRuntime(); Process pr=rt.exec(“cmd /c PATH=%PATH%;c:\\TC\\BIN”); pr=rt.exec(“cmd /cc:\\TC\\BIN\\TCC.exe c:\\TC\\EXAMPLE.c”); pr=rt.exec(“c:\\TC\\EXAMPLE.exe”); BufferedReader input=new BufferedReader(new InputStreamReader(pr.getInputStream())); String line=null; while((line=input.readLine())!=null){ System.out.println(line); } int exitVal=pr.waitFor(); System.out.println(“exited with error code “+exitVal); } catch(Exception e){ System.out.println(e.toString()); //e.printStackTrace(); } } } 但我得到了: java.io.IOException:无法运行程序“c:\ TC \ EXAMPLE.exe”:CreateProcess error = 2,系统找不到指定的文件 […]

Runtime Exec意外停止

我在C中有一个可执行程序,可以为文件生成大量输出。 当我用Runtime调用这个程序时,像这样: Runtime r = Runtime.getRuntime(); Process p = null; p = r.exec(“./my_program -in input.file -out output.file”, null, new File(System.getProperty(“java.io.tmpdir”))); 当程序产生低输出时,一切都还可以,但是当我用大输入调用“* my_program *”时,它会向output.file产生大量输出,但在这种情况下,我的Java程序冻结并没有发生任何事情。 .. 我在终端中用很多大输入测试“* my_program *”并且一切正常,但是当我使用Runtime.exec用Java调用程序时,Java程序就会冻结。 – 提前致谢