我已經編寫了一個編譯和執行C,C++,java程序的java程序..我首先對它進行了測試,它的工作非常好。然後,我測試了它的C,但它給了errors.Please告訴我需要什麼do..Here是編譯代碼的模塊..:通過命令行從java運行一個c/C++程序
public void compileCode(String path,String lang)throws IOException
{
String cmd="";
if(lang.equals("c")||lang.equals("cpp"))
cmd="g++ Main"+threadNum+"."+lang+" -o "+threadNum;
else if(lang.equals("java"))
cmd="javac Main"+threadNum+".java";
Process p=Runtime.getRuntime().exec(cmd,null,new File(path));
String s=null;
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((s = stdError.readLine()) != null) {
msg+=s+"\n";
res=0;
}
if(res!=0)
processCode(path,lang);
}
和錯誤是:
Exception in thread "main" java.io.IOException: Cannot run program "g++" (in directory "C:\wamp\www\usercodes\lokesh"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at Contest.compileCode(Main.java:164)
at Contest.makeFile(Main.java:154)
at Contest.main(Main.java:52)
at Main.main(Main.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:1
20)
? – carmenism
一個愚蠢的問題,但路徑上的g ++? –
我可以從命令promt運行g ++ filename.c -o文件。還有什麼我需要的嗎? 'C:\ wamp \ www \ usercodes \ lokesh> echo%PATH% C:\ Program Files(x86)\ Java \ jdk1.7.0 \ bin; C:\ Program Files(x86)\ CodeBlocks \ MinGW \ bin' –