7

我尝试了很多东西,但由于某种原因,我无法让事情正常进行。我正在尝试使用 Python 脚本运行 MS VS 的 dumpbin 实用程序。

这是我尝试过的(以及对我不起作用的)

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()

dumpbin /EXPORTS C:\Windows\system32\kernel32.dll > tempfile.txt有没有人知道在 Python 中正确地做我想做的事情( )?

4

2 回答 2

8

Popen的参数模式需要一个用于非 shell 调用的字符串列表和一个用于 shell 调用的字符串。这很容易解决。鉴于:

>>> command = '"C:/Program Files/Microsoft Visual Studio 8/VC/bin/dumpbin" /EXPORTS ' + dllFilePath

要么调用subprocess.Popenshell=True

>>> process = subprocess.Popen(command, stdout=tempFile, shell=True)

或使用shlex.split创建参数列表:

>>> process = subprocess.Popen(shlex.split(command), stdout=tempFile)
于 2011-10-19T17:12:55.493 回答
2
with tempFile:
    subprocess.check_call([
        r'C:\Program Files\Microsoft Visual Studio 8\VC\bin\dumpbin.exe',
        '/EXPORTS', 
        dllFilePath], stdout=tempFile)
于 2011-10-19T23:12:24.810 回答