意图
把文件F:\1.cpp 编译链接生成的结果存放在C:\DTS_temp中。编译的语句命令行:
VC的编译器cl编译F:\1.cpp,
调用语句为cl F:\1.cpp (会在当前目录下生成)
现在这样写完,还是在TestCL所在的目录下生成了1.obj文件。
import java.io.*;
public class TestCL {
public static void main(String args[]) {
try {
Runtime.getRuntime().exec("cmd.exe");
Process p = Runtime.getRuntime().exec("cmd /k C:");
p = Runtime.getRuntime().exec("cmd /k cd C:\\DTS_temp");
p = Runtime.getRuntime().exec("cl F:\\1.cpp"); InputStream os = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(os));
String str = br.readLine();
while(str != null)
{
System.out.println(br.readLine());
str = br.readLine();
}
System.out.println("run over");
} catch (Exception e) {
System.err.println("Error");
}
}
}