注:python.exe的路徑已被設置的Java成參數傳遞給一個Python腳本
我試圖創建一個傳遞變量args
(或任何其他變量)到Python腳本的Java程序。
import java.io.*;
public class PythonCallTest{
public static void main (String[] args){
String s = null;
Runtime r = Runtime.getRuntime();
try{
Process p = r.exec("cmd /c python ps.py+",args);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
while ((s = stdInput.readLine()) != null){
System.out.println(s);
}
while ((s = stdError.readLine()) != null){
System.out.println(s);
}
System.exit(0);
}
catch(IOException ioe){
ioe.printStackTrace();
System.exit(-1);
}
}
}
的程序編譯但是當我
java PythonCallTest sender-ip=10.10.10.10
運行它我得到錯誤
「蟒」不被識別爲一個內部或外部的命令,運行程序或批處理文件。
如何正確將字符串中r.exec( 「CMD/C蟒蛇ps.py +」,參數)
編輯
如果我執行以下
Process p = r.exec("cmd /c python ps.py sender-ip=10.251.22.105");
然後該程序起作用。 python.exe的路徑已被設置。我只需要知道如何添加ARGS到r.exec,即如何連接CMD/C蟒蛇ps.py與ARGS
可能的複製http://stackoverflow.com/questions/17953124/python的不被識別爲內部或外部命令爲什麼 –
此外,可能重複的http://stackoverflow.com/questions/14433499/python-is-not-recognized-as-an-內部或外部命令 –
@Andrew_CS如果你說wha,它可能會更容易你認爲問題不在於說問題是重複的。這兩個其他問題可以幫助他解決他的問題,但沒有你說你認爲PATH問題是問題,他們不一定能提供任何幫助。 –