我试图从Java程序调用GNU C编译器来编译c文件,但是我收到一个错误:
这是程序
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);}
}
}
这是我编译和运行程序时得到的结果
$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
这是gcc所在的位置
$which gcc
/usr/bin/gcc
而这里如果是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
任何人都可以帮忙吗?