检查 exe 是 32 位还是 64 位 [英] Checking if an exe is 32 bit or 64 bit

查看:47
本文介绍了检查 exe 是 32 位还是 64 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 python 程序,它使用 scons 构建一个 .exe,然后检查它是 64 位还是 32 位.我尝试了 platform.architecture(test1.exe),但问题是当我提供 32 位 exe 时,它​​说它是 64 位.

I'm writing a python program that uses scons to build an .exe and then checks to see if it's a 64-bit or 32-bit. I tried platform.architecture(test1.exe), but the problem is when I give a 32-bit exe, it says it's a 64-bit.

我尝试使用 dumpbin 但输出很大,所以我使用了这个 dumpin/HEADERS test.exe |find "machine".问题是我不能使用 python 来执行这个命令.当我使用 subprocess.call(['dumpbin/HEADERS test2.exe |find "machine"']) 时,出现以下错误

I tried using dumpbin but the output is huge, so I used this dumpin /HEADERS test.exe |find "machine". The problem is I can't use python to execute this command. When I use subprocess.call(['dumpbin /HEADERS test2.exe |find "machine"']), I get the following error

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

推荐答案

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

You need to specify all the arguments separately:

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

您也可以通过 python 中的输出进行 grep.

You could grep through the output in python just fine too.

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

As an aside: platform.architecture() tells you the current platform architecture you are running scons on, nothing about the binaries you are producing or even how the python version was compiled. It can provide this info for other binaries, but only if the executable points to the Python interpreter, and probably not on Windows as there is no equivalent of the file command present there.

这篇关于检查 exe 是 32 位还是 64 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆