我正在遵循 Jack Crenshaw 的关于构建编译器的指南,将 pascal 和 68k 转换为 java 和 x86。实际的组装过程几乎一帆风顺,只有少数例外。但我尝试使用 Runtime.getRuntime().exec() 集成组装并将生成的程序集链接到 java 程序中。出于某种原因,当从 java 调用时,汇编器会抛出一个错误,但是当我自己调用它时,它可以在命令行中正常工作。这是相关的java代码:
String s = "";
Process p = Runtime.getRuntime().exec("C:\\masm32\\bin\\ml /c /Zd /coff \"" + src.getAbsolutePath() + "\"");
p.waitFor();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
System.out.println("\n");
p = Runtime.getRuntime().exec("C:\\masm32\\bin\\Link /SUBSYSTEM:CONSOLE \"" + obj.getAbsolutePath() + "\"");
p.waitFor();
stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
System.out.println("\n");
p = Runtime.getRuntime().exec("\"" + exe.getAbsolutePath() + "\"");
p.waitFor();
stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
错误
Assembling: C:\asm\tobecompiled.asm
C:\asm\tobecompiled.asm(1) : error A2088: END directive required at end of file