【发布时间】:2012-06-19 16:58:02
【问题描述】:
我正在编写一个使用 scons 构建 .exe 的 python 程序,然后检查它是 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
【问题讨论】:
-
错误是路径问题,找不到可执行文件/脚本。
-
如果您要启动 SCons 来构建可执行文件,为什么需要知道它是否为 32/64 位?我认为您可以在 SCons 中通过构建您传递给它的选项来控制它。
-
@Brady:它找不到名为
'dumpbin /HEADERS test2.exe |find "machine"'的二进制文件,没有.. -
@MartijnPieters,好的,我明白了,谢谢。
-
对于 Python3,请查看此帖子:stackoverflow.com/questions/61999530/… 并从@L3viathan 中寻找答案。它就像一个魅力!