我已經能夠在Eclipse中編譯一個完美工作的C程序。我已經安裝了python解釋器,並且已經在Windows中設置了環境變量。是否可以通過命令提示符在Eclipse中編譯Python源文件?
這些是C的代碼如何修改它來編譯的.py(Python)的源File.Thanks
public class C_Compile {
public static void main(String args[]){
String ret = compile();
System.out.println(ret);
}
public static String compile()
{
String log="";
String myDirectory = "C:\\";
try {
String s= null;
//change this string to your compilers location
Process p = Runtime.getRuntime().exec("cmd /C gcc Hello.c", null, new java.io.File(myDirectory));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
boolean error=false;
log+="";
while ((s = stdError.readLine()) != null) {
log+=s;
error=true;
log+="\n";
}
if(error==false) log+="Compilation Successful !!!";
} catch (IOException e) {
e.printStackTrace();
}
return log;
}
public int runProgram()
{
int ret = -1;
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd.exe /c start a.exe");
proc.waitFor();
ret = proc.exitValue();
} catch (Throwable t)
{
t.printStackTrace();
return ret;
}
return ret;
}}
好的。你究竟想要做什麼?編寫一個運行python程序的eclipse插件? – Cubic 2013-02-17 13:53:46
你不需要編譯python源文件,它們是在運行時解釋的 – yurib 2013-02-17 13:54:23
@yurib儘管你可以將它們編譯爲字節碼。 – Cubic 2013-02-17 13:57:56