运行 使用 Python 获取参数的可执行文件

Running executable that takes arguments using Python

我正在编写一个小 python 脚本,我在其中打开一个现有的可执行文件 (.exe) 并发送一个字符串作为参数。

我正在使用 subprocess.call 方法,但出现以下错误:

File "C:\Python34\lib\subprocess.py", line 537, in call
   with Popen(*popenargs, **kwargs) as p:
File "C:\Python34\lib\subprocess.py", line 767, in __init__
   raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

我的代码

import os
import subprocess

x = subprocess.call("C:\Users\Desktop\Program\Program.exe", y)

其中 y 是我传递的字符串。

我正在尝试升级旧的 VB 代码。原始代码调用可执行文件并传递参数,如下所示。我正在尝试在 Python.

中复制它
Private comm As ExecCmd
Dim cmd As String
Dim app As String
Dim e As New ExecCmd

exec_1= "...\Desktop\Program.exe"
x = "Text" & Variable & " Hello" & Variable2

comm.StartApp exec_1, x   'starts the .exe file with an argument

首先将程序和您想要的任何参数放入一个数组中。

import os
import subprocess

x = subprocess.call(["C:\Users\Desktop\Program\Program.exe", y])

命令和参数应该在列表中

x = subprocess.call(["C:\Users\Desktop\Program\Program.exe", y])

Documentation