这是用eclipse编写的代码的一部分。
我正在为编译器制作一个GUI,这是按下编译按钮时执行的操作。
File file = fileChooser.getSelectedFile();
try {
FileWriter out = new FileWriter(file);
textContent.write(out);
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
String filepath = file.getPath();
String filepath2 = filepath.substring(0, filepath.lastIndexOf(File.separator));
System.out.println(filepath);
System.out.println(filepath2);
String name = file.getName();
String name2 = file.getName().substring(0, file.getName().lastIndexOf("."));
String folder = filepath2+"\\";
String o = folder+name2+".o";
System.out.println(o);
ProcessBuilder pb=new ProcessBuilder();
try {
pb = new ProcessBuilder("cmd", "/C", "arm-none-eabi-gcc "+"-c "+"-march=armv8-a "+"-g " + "\"" + filepath2 + "\\" +name + "\"" + " -o \""+ name2+"\"");
pb = new ProcessBuilder("cmd", "/C", "arm-none-eabi-g++ "+"-c "+"-march=armv8-a "+"-g " + "\"" + filepath2 + "\\" +name + "\"" + " -o \""+ name2+"\"");
pb.directory(new File(filepath2));
Process p = pb.start();
p.waitFor();
int x = p.exitValue();
if (x == 0) {
area.setForeground(red);
area.setText(" == 0 error.. Compilation Finished");
} else {
BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
//BufferedWriter rm=new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
String out;
area.setText("");
while ((out = r.readLine()) != null)
{
area.setForeground(RED);
area.append(out + System.getProperty("line.separator"));
}
}
} catch (Exception ex) {
ex.printStackTrace();
输出:
当我编译程序(test.cpp)时,它只是创建一个测试文件,我希望测试输出。
控制台: