【发布时间】:2018-08-15 01:31:39
【问题描述】:
我尝试从 Java 运行 Linux shell 命令。这些命令直接在 shell 上运行良好,但总是崩溃。
我有一个 makefile,我尝试通过 Java 运行 make。
我的 Java 代码:
String command = "make generate FILE=" + name ;
String [] envp = { } ;
File dir = new File ( System.getProperty("user.dir")) ;
Process proc = Runtime.getRuntime().exec(command,envp,dir);
proc.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);
}
我的生成文件:
generate:
llvm-as -f VSOP_Executable/$(FILE).ll -o $(FILE).bc
llc $(FILE).bc
gcc -c $(FILE).s -o $(FILE).o
gcc $(FILE).o -o $(FILE) -no-pie
它总是在我尝试生成可执行文件的最后一行崩溃。
错误:
makefile:47: 目标“生成”的配方失败
【问题讨论】:
-
我有一个 makefile,我尝试通过 java 运行 make。 为什么?
-
你检查过你的环境变量了吗? PATH、LDLIBRARY 等?
-
其实就是这个问题,因为你设置环境为空,所以找不到llvm-as、llc、gcc,gcc也找不到链接。
-
Process::waitFor如有必要,使当前线程等待,直到此 Process 对象表示的进程终止。 为什么您希望能够读取输入流终止的进程?我错过了什么吗? -
@ElliottFrisch 制作文件已经制作完成。即使我尝试直接在代码中运行命令,而不使用 make 文件。同样的问题。最后一个命令不起作用。