我如何创建.o文件?

时间:2016-06-17 07:19:31

标签: java eclipse swing

这是用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)时,它只是创建一个测试文件,我希望测试输出。 output

控制台:

实际上,它在控制台中显示它已创建了一个test.o文件 console

0 个答案:

没有答案