python - 检查 exe 是 32 位还是 64 位

标签 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

最佳答案

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

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

你也可以用 python 来 grep 输出结果。

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

关于python - 检查 exe 是 32 位还是 64 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11097535/

相关文章:

scons - 我可以使用 SCons 显示构建进度吗?

python - SCons - 转换目录中的所有图像

python - 查找长度为 3 的总组合,使得总和可被给定数字整除且 i<j<k

Python:类属性,默认为父级的值,并且可用于整个层次结构

python - 可视化部分相关性

linux - .c 文件的注释改了,scons 还是要重新编译?

android - 为嵌入 SCons 的 ARM 交叉编译 Swiften 库

SConscript 环境错误 : No module named compilation_db

python - SQL Group By 与 Python Group By 错误对比

python - 太多值无法在python中解压缩?