我可以沒有任何問題運行命令行命令(驗證腳本執行):的Java的Runtime.exec()
c:/Python27/python ../feedvalidator/feedvalidator/src/demo.py https://das.dynalias.org:8080/das_core/das/2.16.840.1.113883.4.349/1012581676V377802/otherAdminData/careCoordinators
,並從Java,如果我離開過的URL參數,只是做:
String[] args1 = {"c:/Python27/python", "../feedvalidator/feedvalidator/src/demo.py" };
Runtime r = Runtime.getRuntime();
Process p = r.exec(args1);
它工作正常。如果我使用某些參數的URL如:
String[] args1 = {"c:/Python27/python", "../feedvalidator/feedvalidator/src/demo.py" , "http://www.intertwingly.net/blog/index.atom"};
// or
String[] args1 = {"c:/Python27/python", "../feedvalidator/feedvalidator/src/demo.py" , "http://www.cnn.com"};
它也正常工作。
但是,如果我使用這個特定的URL https://das.dynalias.org:8080/das_core/das/2.16.840.1.113883.4.349/1012581676V377802/otherAdminData/careCoordinators,那麼腳本只是掛起(Java等待過程完成)。我不知道爲什麼它從該URL的命令行工作,但不是從一個Java程序。我試圖添加引號來圍繞URL參數,但這也不起作用。我在URL中看不到任何我認爲需要轉義的字符。
全碼:
String urlToValidate = "https://das.dynalias.org:8080/das_core/das/2.16.840.1.113883.4.349/1012581676V377802/otherAdminData/careCoordinators";
String[] args1 = {"c:/Python27/python", "C:/Documents and Settings/vhaiswcaldej/DAS_Workspace/feedvalidator/feedvalidator/src/demo.py", urlToValidate };
System.out.println(args1[0] + " " + args1[1] + " " + args1[2]);
Runtime r = Runtime.getRuntime();
Process p = r.exec(args1);
BufferedReader br = new BufferedReader(new InputStreamReader(
p.getInputStream()));
int returnCode = p.waitFor();
System.out.println("Python Script or OS Return Code: " + Integer.toString(returnCode));
if (returnCode >= 2) {
.out.println("OS Error: Unable to Find File or other OS error.");
}
String line = "";
while (br.ready()) {
String str = br.readLine();
System.out.println(str);
if (str.startsWith("line")) {
//TODO: Report this error back to test tool.
//System.out.println("Error!");
}
}
也許當前目錄確實重要嗎?你可以嘗試在命令行切換到另一個目錄。 – Yogu 2011-12-21 20:19:44
你應該檢查在Linux上執行的實際命令行 - 'ps f',在Win - sysinternals ProcessExplorer – 2011-12-21 20:26:51
這可能是一個ssl問題。你可以嘗試調用一個http端點來驗證它嗎? – phoet 2011-12-21 20:57:12