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

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

本文介绍了ProcessBuilder无法使用参数运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我有一个通过ProcessBuilder运行的python脚本.一切正常.我遇到的问题是,每当我将参数传递给python脚本时,python脚本都会以无法识别的参数进行响应.但是,如果我采用确切的命令并将其复制并粘贴到命令提示符下,则它将运行得非常好.有什么帮助吗?这是我现在所拥有的一般想法:

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

推荐答案

将两个单独的参数传递给 ProcessBuilder ,而不是并置-arg1 argumentValue :

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

否则,要执行的程序将看到一个无法识别的单个参数-arg1 argumentsValue .

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

这篇关于ProcessBuilder无法使用参数运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:01