Python找不到System32

时间:2017-01-13 08:25:45

标签: python windows python-2.7

我想打开一个我创建的exe,它位于Windows的System32文件夹中。我通过命令这样做:

subprocess.call(["C:\\Windows\\System32\\ListTest.exe"])

但不知何故Python没有找到System32文件夹。我将我的exe复制到" System" Windows中的目录,如果我想通过Python打开exe,一切正常。为什么Python找不到System32目录?

2 个答案:

答案 0 :(得分:1)

@eryksun和@Keith Hall得到了正确答案。

由于我使用的是32位python的64位操作系统,因此它看起来位于错误的目录中。

system32 = os.path.join(os.environ['SystemRoot'], 'SysNative' if 
platform.architecture()[0] == '32bit' else 'System32')
listtest_path = os.path.join(system32, 'ListTest.exe')
subprocess.call([listtest_path])

现在是完整的代码

答案 1 :(得分:0)

尝试shell =True

import subprocess
subprocess.call('dir', shell=True)
相关问题