Reputation: 111
I am trying to compile a C file from Java by calling Cygwin's gcc or gcc-4, but nothing I try seems to work. What I am trying is the following line of code:
theProcess = Runtime.getRuntime().exec("cmd /c C:/cygwin/bin/gcc-4.exe -o C:/work/source.exe C:/work/source.c");
However, it did not output anything.
Upvotes: 3
Views: 580
Reputation: 4657
I would need to see more about what you are doing with theProcess
after this statement to understand this fully. But simply calling "exec" will not output anything to the Std output, if that is what you are expecting. In some cases, commands will not execute at all if their output is not consumed. That being said, you will need to read the output from the Process
object that was created. Try something like this:
BufferedReader br = new BufferedReader (new InputStreamReader (theProcess.getInputStream());
String line = br.readLine();
while (line != null) {
System.out.println(line);
line = br.readLine();
}
This will print the output from the process' standard output to the JVM's standard output.
Upvotes: 1