I am trying to call the GNU C compiler from a Java program to compile c++ file, but I get an error:
Here is the program
class HelloWorld {
public static void main(String[] args) {
Runtime sys = Runtime.getRuntime();
System.out.println("Hello World!");
try {
String com = "g++ NB.cpp -o NNN";
System.out.println(com);
Process p = sys.exec(com);
}
catch (Exception ep) {
System.err.println(ep);}
}
}
Here is what I get when I compiler and run the program
$javac HelloWorld.java
$java HelloWorld
Hello World!
gcc NB.cpp -o NB
java.io.IOException: Cannot run program "g++": CreateProcess error=5, Access is denied
Here is where the gcc is resides
$ which gcc
/usr/bin/gcc
And here if the contents of the PATH
$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin:/cygdrive/c/Program Files (x86)/MiKTeX 2.9/miktex/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windo
ws/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/d/SourceForge/vectorpascalcom: D:/Cygwin/bin:/cygdrive/d/make382:/cygdrive/d/usr/bin:/cygdrive/d/Program Files/TortoiseSV
N/bin:/cygdrive/d/SourceForge/vectorpascalcom:/usr/bin:/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin
Can any one help?
g++run from the command prompt and it'll run from Java too.