简体   繁体   English

ProcessBuilder无法使用参数运行python脚本

[英]ProcessBuilder cannot run python script with arguments

Ok, so I have a python script that I am running through ProcessBuilder. 好的,所以我有一个python脚本,我正在通过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 . 我遇到的问题是每当我将参数传递给python脚本时,python脚本都会以一个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();

Pass two separate arguments to ProcessBuilder instead of concatenating --arg1 and argumentValue : 将两个单独的参数传递给ProcessBuilder而不是连接--arg1argumentValue

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. 否则,要执行的程序将看到一个它无法识别的参数--arg1 argumentValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM