简体   繁体   English

使用带参数的Python调用外部* .exe,没有错误,但是没有输出

[英]Calling external *.exe with Python with arguments, no errors but getting no output

I have *.exe program which takes simple command to create a user (in cmd): I open cmd, navigate to my.exe location, then run it like that: 我有* .exe程序,它使用简单的命令来创建用户(以cmd为单位):我打开cmd,导航到my.exe位置,然后像这样运行它:

my.exe cu username password email my.exe cu用户名密码电子邮件

cu - is a command that is used by my.exe to create users. cu-是my.exe用于创建用户的命令。

As I have many users to create, I want to run my.exe with python. 由于要创建许多用户,因此我想使用python运行my.exe。

I am getting no errors but users are not created. 我没有收到任何错误,但是没有创建用户。 I have done it manually in cmd and no problems. 我已经在cmd中手动完成了,没有问题。 As I am not familiar with this module of python, I don't quite understand what's going on. 因为我不熟悉python的这个模块,所以我不太了解发生了什么。

My script: 我的剧本:

# import details for users from csv and write them to a list:
import csv
with open(r'C:\temp\test.csv', 'rb') as f:
    reader = csv.reader(f)
    users_list = list(reader) # list of lists

# run my.exe for each list entry, each is a list as well
import subprocess
for each in users_list:
    arguments = 'cu' +" "+ str(each[0])  +" "+ str(each[1]) +" "+ str(each[2])
    subprocess.call([r"C:\Software\ikfbatool\ikfbatool.exe", arguments])

You want to pass the arguments as a long string and it is not correct. 您想将参数作为长字符串传递,这是不正确的。 In your case your list will contain 2 elements, only the .exe and a string which contains the arguments. 在您的情况下,您的列表将包含2个元素,只有.exe和包含参数的字符串。

All members of command should be separated in list. 命令的所有成员应在列表中分开。

You should try: 你应该试试:

arguments = ['cu', str(each[0]), str(each[1]), str(each[2])]
subprocess.call([r"C:\Software\ikfbatool\ikfbatool.exe"].extend(arguments))

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

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