【发布时间】:2019-12-17 22:29:15
【问题描述】:
我正在使用 32 位 python 的 Windows Server 2012 R2 standard 机器上运行。
我正在尝试为 64 位系统运行 powershell 脚本,以检查注册表中是否存在密钥:
$path = "Registry::HKLM\Software\<folder>"
if (!(Test-Path $path))
{
write "$path does not exist!"
}
通过 powershell 运行时,脚本运行良好。
当我从 python 运行它时,它找不到密钥:
from gevent.subprocess import call
call("powershell <script.ps1>, shell=True")
经过一番研究,发现32位的python进程调用的是32位版本的powershell。
我用这个简单的脚本验证了它,它检查正在运行的进程是 32 位还是 64 位:
powershell [System.Environment]::Is64BitProcess
对于 64 位进程将返回 True,对于 32 位进程将返回 False。
手动检查此命令是否有效:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe [System.Environment]::Is64BitProcess
返回 False,因为这是 32 位版本的 powershell(是的,由于 WOW64 文件夹,相当混乱)。
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe [System.Environment]::Is64BitProcess
返回True。
但运行:
from gevent.subprocess import call
call("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe [System.Environment]::Is64BitProcess", shell=True)
返回False
我错过了什么?
【问题讨论】:
标签: python powershell 32bit-64bit