执行" $ aarch64-linux-objdump -d a.out n#39;在终端通过java

时间:2015-04-18 11:59:02

标签: java c++ linux terminal

我使用gcc制作了一个交叉编译器。现在我想通过java程序在终端中执行编译和运行命令。以下是我正在使用的代码:

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Runterminal {

public static void main(String[] args) {

Process proc;
Process procRun; 
String compileCommand = "aarch64-linux-g++ -std=c++14 test.cpp";
String runCommand = "aarch64-linux-objdump -d a.out";
try{

      proc = Runtime.getRuntime().exec(compileCommand);
      procRun = Runtime.getRuntime().exec(runCommand);
  // Read the output

BufferedReader reader =  
      new BufferedReader(new InputStreamReader(proc.getInputStream()));

String line = "";
while((line = reader.readLine()) != null) {
    System.out.print(line + "\n");
}

proc.waitFor();   

BufferedReader readero =  
      new BufferedReader(new InputStreamReader(procRun.getInputStream()));

String lineo = "";
while((lineo = readero.readLine()) != null) {
    System.out.print(lineo + "\n");
}

procRun.waitFor();   

}
 catch(Exception e)
 {

  System.out.println("Exception occurred "+e);
    }

   }
 } 

现在我的第一个命令正在执行,因为我可以看到正在生成a.out文件。第二个命令应该转储文件的内存内容,它应该在终端打印,但我没有看到任何输出。谁能告诉我哪里出错?

0 个答案:

没有答案