簡體   English   中英

使用帶參數的Python調用外部* .exe,沒有錯誤,但是沒有輸出

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

我有* .exe程序,它使用簡單的命令來創建用戶(以cmd為單位):我打開cmd,導航到my.exe位置,然后像這樣運行它:

my.exe cu用戶名密碼電子郵件

cu-是my.exe用於創建用戶的命令。

由於要創建許多用戶,因此我想使用python運行my.exe。

我沒有收到任何錯誤,但是沒有創建用戶。 我已經在cmd中手動完成了,沒有問題。 因為我不熟悉python的這個模塊,所以我不太了解發生了什么。

我的劇本:

# 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])

您想將參數作為長字符串傳遞,這是不正確的。 在您的情況下,您的列表將包含2個元素,只有.exe和包含參數的字符串。

命令的所有成員應在列表中分開。

你應該試試:

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