[英]Why does subprocess.Popen not work
I tried a lot of things but for some reason I could not get things working. 我尝试了很多东西,但由于某种原因,我无法让事情奏效。 I am trying to run dumpbin utility of MS VS using a Python script. 我试图使用Python脚本运行MS VS的dumpbin实用程序。
Here are what I tried (and what did not work for me) 这是我尝试过的(以及对我不起作用的东西)
1. 1。
tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath
process = subprocess.Popen(command, stdout=tempFile)
process.wait()
tempFile.close()
2. 2。
tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
command = 'C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin /EXPORTS ' + dllFilePath
process = subprocess.Popen(command, stdout=tempFile)
process.wait()
tempFile.close()
3. 3。
tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')
process = subprocess.Popen(['C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin\\dumpbin', '/EXPORTS', dllFilePath], stdout = tempFile)
process.wait()
tempFile.close()
does anyone have any idea on doing what i am trying to do ( dumpbin /EXPORTS C:\\Windows\\system32\\kernel32.dll > tempfile.txt
) correctly in Python? 有没有人有任何想法在Python中正确地做我想做的事( dumpbin /EXPORTS C:\\Windows\\system32\\kernel32.dll > tempfile.txt
)?
The argument pattern for Popen expect a list of strings for non-shell calls and a string for shell calls. Popen的参数模式期望非shell调用的字符串列表和shell调用的字符串。 This is easy to fix. 这很容易解决。 Given: 鉴于:
>>> command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath
Either call subprocess.Popen with shell=True
: 使用shell=True
调用subprocess.Popen :
>>> process = subprocess.Popen(command, stdout=tempFile, shell=True)
or use shlex.split to create an argument list: 或使用shlex.split创建参数列表:
>>> process = subprocess.Popen(shlex.split(command), stdout=tempFile)
with tempFile:
subprocess.check_call([
r'C:\Program Files\Microsoft Visual Studio 8\VC\bin\dumpbin.exe',
'/EXPORTS',
dllFilePath], stdout=tempFile)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.