0

Calling gcc compiler in a Java Source to compile a C file.

  List<String> command = new ArrayList<String>();
  String fs = System.getProperty("file.separator");
  command.add("C:\\cygwin" + fs + "bin" + fs + "sh");
  command.add("-c");
  command.add("/usr/bin/gcc /cygdrive/d/WorkSpace/TEST/HelloWorld.c -o /cygdrive/d/WorkSpace/HHH");
  ProcessBuilder builder = new ProcessBuilder(command);
  final Process process = builder.start();

HHH.exe is not created. Can somebody explain me what is wrong with this code?

4

1 回答 1

1

您需要将字符串“cmd”和“/c”设置为命令列表中的前两个元素。从 Java 调用任何命令行进程时,这是必需的。

于 2012-08-01T22:29:36.650 回答