ProcessBuilder cannot run python script with argum

2019-02-20 21:58发布

问题:

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.