Checking if an exe is 32 bit or 64 bit

北城以北 提交于 2020-06-16 04:42:49

问题


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.

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

回答1:


You need to specify all the arguments separately:

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

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

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.



来源:https://stackoverflow.com/questions/11097535/checking-if-an-exe-is-32-bit-or-64-bit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!