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の引数パターンは、非シェル呼び出しの文字列のリストとシェル呼び出しの文字列を想定しています。これは簡単に修正できます。与えられた:

>>> 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 に答える