這是python腳本會做的。問題是如何在函數內調用外部cmd文件?如何在python腳本中調用cmd文件
- 讀取目錄中的CSV文件。
- 如果在第6列中的內容等於「批准」,然後調用一個 外部Windows腳本「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
有很多解決方案看看一些問題就像http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python,也看看http://www.doughellmann.com/PyMOTW/subprocess/ – pyfunc