我试图创建一个python可执行文件,它将运行多个wmic调用来检查可移植可执行文件的版本。
以下代码在命令提示符下工作,因此我尝试从python
运行相同的行wmic datafile where name="C:\\Program Files\\Internet Explorer\\iexplore.exe" get Version /value
Python代码:
import subprocess
spath = r'C:\Program Files\Internet Explorer\iexplore.exe'
cargs = ["wmic","datafile","where", r'name="{0}"'.format(spath), "get", "Version", "/value"]
process = subprocess.check_output(cargs)
我收到以下错误
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-59-3271c59ed48f> in <module>()
----> 1 process = subprocess.check_output(cargs)
c:\users\jhsiang\appdata\local\programs\python\python35\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
624
625 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 626 **kwargs).stdout
627
628
c:\users\jhsiang\appdata\local\programs\python\python35\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
706 if check and retcode:
707 raise CalledProcessError(retcode, process.args,
--> 708 output=stdout, stderr=stderr)
709 return CompletedProcess(process.args, retcode, stdout, stderr)
710
CalledProcessError: Command '['wmic', 'datafile', 'where', 'name="C:\\Program Files\\Internet Explorer\\iexplore.exe"', 'get', 'Version', '/value']' returned non-zero exit status 2147749911
错误消息末尾的命令对我来说是正确的。我哪里错了?