【发布时间】:2011-10-17 15:04:33
【问题描述】:
我正在尝试从 python 启动一个 PowerShell 脚本,如下所示:
psxmlgen = subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'./buildxml.ps1',
arg1, arg2, arg3], cwd=os.getcwd())
result = psxmlgen.wait()
问题是我收到以下错误:
文件 C:\Users\sztomi\workspace\myproject\buildxml.ps1 无法加载,因为在此禁用了脚本的执行 系统。有关详细信息,请参阅“get-help about_signing”。
尽管事实上我很久以前确实通过在管理员运行的 PS 终端中键入 Set-ExecutionPolicy Unrestriced 来启用在 Powershell 中运行脚本(为了确保再次这样做)。 powershell 可执行文件与开始菜单中的快捷方式指向的相同。 Get-ExecutionPolicy 正确报告 Unrestricted 无论我是否以管理员身份运行 PowerShell。
如何从 Python 中正确执行 PS 脚本?
【问题讨论】:
标签: python powershell