我正在编写一个 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/