Python 找不到 System32 [英] Python does not find System32

查看:28
本文介绍了Python 找不到 System32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to open up an exe I created, which is in the System32 folder of Windows. I do so through the command:

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

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

But somehow Python does not find the System32 folder. I copied my exe over to the "System" directory in Windows, and if I want to open the exe there through Python, everything works fine. Why does Python not find the System32 directory?

推荐答案

@eryksun 和 @Keith Hall 给出了正确答案.

@eryksun and @Keith Hall had the right answer.

由于我使用的是带有 32 位 python 的 64 位操作系统,所以它看起来在错误的目录中.

Since I am using a 64bit OS with a 32bit python it looks in the wrong directory.

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])

现在是完整的代码

这篇关于Python 找不到 System32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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