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:
my.exe cu username password email
cu - is a command that is used by my.exe to create users.
As I have many users to create, I want to run my.exe with python.
I am getting no errors but users are not created. I have done it manually in cmd and no problems. As I am not familiar with this module of python, I don't quite understand what's going on.
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.
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.