2

scons を使用してビルドし.exe、64 ビットか 32 ビットかを確認する python プログラムを作成しています。を試しplatform.architecture(test1.exe)ましたが、問題は 32 ビットの exe を指定すると、64 ビットだと表示されることです。

使ってみdumpbinましたが出力が大きいのでこちらを使用しましdumpin /HEADERS test.exe |find "machine"た。問題は、python を使用してこのコマンドを実行できないことです。を使用するsubprocess.call(['dumpbin /HEADERS test2.exe |find "machine"'])と、次のエラーが表示されます

Traceback (most recent call last):
  File "test_scons.py", line 66, in <module>
    print "Architecture of the compiled program is ",subprocess.call(["dumpbin /HEADERS test2.exe |find ""machine" ])
  File "C:\Python27\lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
4

1 に答える 1

5

すべての引数を個別に指定する必要があります。

subprocess.call(['dumpbin', '/HEADERS', 'test2.exe', '|', 'find', '"machine"'])

Pythonで出力をgrepすることもできます。

余談platform.architecture()ですが、scons を実行している現在のプラットフォーム アーキテクチャはわかりますが、生成しているバイナリや、python バージョンがどのようにコンパイルされたかについては何もわかりません。他のバイナリにこの情報を提供できますが、実行可能ファイルが Python インタープリターを指している場合のみであり、Windows にはfileコマンドに相当するものが存在しないため、おそらくそうではありません。

于 2012-06-19T08:51:54.833 に答える