【发布时间】:2026-02-01 18:05:03
【问题描述】:
我有一个 Windows Server 2008 机器。我以管理员身份在 powershell Set-ExecutionPolicy Unrestricted 中运行。当我运行 powershell Get-ExecutionPolicy 时,它返回 Unrestricted。
我创建了一个 .bat 文件,其中展示了我所看到的问题。 .bat 文件 test.bat 只有一行,powershell Get-ExecutionPolicy。当我打开命令提示符并运行 test.bat 时,屏幕上会显示“Unrestricted”。
如果我运行以下 python 脚本,
import subprocess
subprocess.Popen("test.bat")
“受限”打印到屏幕上。从 Python 的 subprocess.Popen 运行时,此设置有何不同?我没有在我拥有的 Windows 7 机器上看到这个问题,我在其中执行了相同的工作流程。
【问题讨论】:
-
我找到了答案。 Unrestricted ExecutionPolicy 适用于 64 位版本的 powershell。 Python 最终调用了我没有设置的 32 位版本。 Windows Server 2008 包含两个版本的 powershell,但 Windows 7 没有。详情请见:*.com/questions/4037939/…
-
你可以把它作为一个答案,然后接受它。
-
是的,但我不得不等待 8 小时,因为我的代表太低了。
标签: python windows powershell executionpolicy