ProcessBuilder cannot run python script with arguments

纵然是瞬间 提交于 2019-12-01 12:01:14

问题


Ok, so I have a python script that I am running through ProcessBuilder. Everything is working fine. The issue I am having is whenever I pass arguments into the python script, the python script responds with a unrecognized argumets. BUT if I take the exact command and copy and paste it into the command prompt, it runs perfectly fine. Any help? Here is the general idea of what I have right now:

ProcessBuilder builder = new ProcessBuilder("C:\Python33\" + "python.exe","-u", "C:\...\script.py", "--arg1 " + "argumentValue");
p = builder.start();

回答1:


Pass two separate arguments to ProcessBuilder instead of concatenating --arg1 and argumentValue:

ProcessBuilder builder = new ProcessBuilder("C:\\Python33\\python.exe",
                                            "-u",
                                            "C:\\...\\script.py,
                                            "--arg1",
                                            "argumentValue");

Otherwise the program to be executed will see a single argument --arg1 argumentValue that it does not recognise.



来源:https://stackoverflow.com/questions/15980057/processbuilder-cannot-run-python-script-with-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!