为什么 subprocess.Popen 不起作用 [英] Why does subprocess.Popen not work
问题描述
我尝试了很多东西,但由于某种原因,我无法让一切正常工作.我正在尝试使用 Python 脚本运行 MS VS 的 dumpbin 实用程序.
这是我尝试过的(以及对我不起作用的)
1.
tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')命令 = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin"/EXPORTS ' + dllFilePathprocess = subprocess.Popen(command, stdout=tempFile)进程等待()tempFile.close()
2.
tempFile = open('C:\\Windows\\temp\\tempExports.txt', 'w')命令 = 'C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin/EXPORTS' + dllFilePathprocess = subprocess.Popen(command, stdout=tempFile)进程等待()tempFile.close()
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)进程等待()tempFile.close()
有没有人知道在 Python 中正确地做我想做的事情 (dumpbin/EXPORTS C:\Windows\system32\kernel32.dll > tempfile.txt
)?
Popen 的参数模式需要一个用于非 shell 调用的字符串列表和一个用于 shell 调用的字符串列表.这很容易修复.鉴于:
<预><代码>>>>命令 = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin"/EXPORTS ' + dllFilePath使用 shell=True
调用 subprocess.Popen :
或使用 shlex.split 创建参数列表:
<预><代码>>>>process = subprocess.Popen(shlex.split(command), stdout=tempFile)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.
Here are what I tried (and what did not work for me)
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.
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.
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?
The argument pattern for Popen expect a list of strings for non-shell calls and a string for shell calls. 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
:
>>> process = subprocess.Popen(command, stdout=tempFile, shell=True)
or use shlex.split to create an argument list:
>>> process = subprocess.Popen(shlex.split(command), stdout=tempFile)
这篇关于为什么 subprocess.Popen 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!