ageoff
ageoff

Reputation: 2828

ProcessBuilder cannot run python script with arguments

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();

Upvotes: 1

Views: 5114

Answers (1)

hmjd
hmjd

Reputation: 121971

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.

Upvotes: 7

Related Questions