【发布时间】:2014-02-28 07:04:11
【问题描述】:
如何在 Python 中正确执行这个 Unix 命令,将给定的值 index, username, password 代入命令中?
abc.py
import subprocess,datetime
cmd = '\./splunk search "| dbinspect index=%s |timeformat= "%s" rename state as category | stats min(earliestTime) as earliestTime max(latestTime) as latestTime sum(sizeOnDiskMB) as MB by category " -auth %s:%s | grep -v "category" | grep -v "-"' %(index, username, password)
subprocess.call(cmd, shell = True)
当我尝试执行命令时,我得到了错误:
TypeError: not enough arguments for format string
【问题讨论】:
-
你只需要逃避它:
timeformat= "%%s" -
它的错误类似于未知命令'timeformat'
标签: python python-2.7 subprocess