检查 exe 是 32 位还是 64 位

cyb*_*mon 2 python scons

我正在编写一个 python 程序,它使用 scons 来构建一个.exe,然后检查它是 64 位还是 32 位。我试过了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
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 5

您需要单独指定所有参数:

subprocess.call(['dumpbin', '/HEADERS', 'test2.exe', '|', 'find', '"machine"'])
Run Code Online (Sandbox Code Playgroud)

您也可以通过 python 中的输出 grep 就好了。

顺便说一句:platform.architecture()告诉你当前的平台架构,您正在运行使用SCons,没有什么关于你正在生产或Python的版本,甚至如何编译的二进制文件。它可以为其他二进制文件提供此信息,但前提是可执行文件指向 Python 解释器,并且可能不在 Windows 上,因为那里没有等效的file命令。