gpt4 book ai didi

python - 如何在python脚本中调用cmd文件

转载 作者:太空狗 更新时间:2023-10-30 02:49:24 25 4
gpt4 key购买 nike

这是 python 脚本会做的。问题是如何在函数内部调用外部cmd文件?

  • 读取目录中的 CSV 文件。
  • 如果第 6 列的内容等于“已批准”,则调用外部窗口脚本“TransferProd.cmd”

.

def readCSV(x):
#csvContents is a list in the global scope that will contain lists of the
#items on each line of the specified CSV file
try:
global csvContents
file = open(csvDir + x + '.csv', 'r') #Opens the CSV file
csvContents = file.read().splitlines() #Appends each line of the CSV file to csvContents
#----------------------------------------------------------------------
#This takes each item in csvContents and splits it at "," into a list.
#The list created replaces the item in csvContents
for y in range(0,len(csvContents)):
csvContents[y] = csvContents[y].lower().split(',')
if csvContents[y][6] == 'approved':
***CALL TransferProd.cmd***
file.close()
return
except Exception as error:
log(logFile, 'An error has occurred in the readCSV function: ' + str(error))
raise

最佳答案

看看 subprocess module .

import subprocess
p = subprocess.Popen(['TransferProd.cmd'])

您可以指定输出/错误的去向(直接到文件或类似文件的对象)、管道输入等。

关于python - 如何在python脚本中调用cmd文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8407279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com