我试图从Java执行一个python脚本。当我手动执行python脚本时,它正常工作。当我从Java执行它时,它的参数有问题:事实上,python的响应是“Usage”错误,就像我没有传递参数一样。在
Java代码:String pythonCommand="python /path/to/myscript.py --key='value list here' -otherparam=param";
p = Runtime.getRuntime().exec(pythonCommand);
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
p.waitFor();
logger.debug("Exit value: "+p.exitValue());
while ((line = input.readLine()) != null) {
logger.debug("Python command output: " +line);
}
while ((line = error.readLine()) != null) {
logger.debug("Python command ERROR output: " +line);
}
input.close();
我重复一遍,如果我只是复制粘贴并按字面意思执行“pythonCommand”字符串中的内容,那么脚本正常工作,但是如果我从Java执行它,它会说:
^{pr2}$
有什么问题吗?在
编辑:另一个重要信息!如果我执行一个没有参数的Python脚本,比如“Python/path/to”/测试.py“它工作得很好。在
edit2:我尝试过执行一个Python脚本,它不包含带有“or”的多单词参数,并且它起作用了。所以多字参数肯定是问题所在。我该怎么通过他们?在