您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

从Python调用PowerShell脚本

从Python调用PowerShell脚本

首先,Set-ExecutionPolicy Unrestriced基于每个用户和每个位数(32位与64位不同)。

其次,您可以从命令行覆盖执行策略。

psxmlgen = subprocess.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
                             '-ExecutionPolicy',
                             'Unrestricted',
                             './buildxml.ps1',
                             arg1, arg2, arg3], cwd=os.getcwd())
result = psxmlgen.wait()

显然,您可以使用以下路径从32位PowerShell访问64位PowerShell(感谢@eryksun):

powershell64 = os.path.join(os.environ['SystemRoot'], 
    'SysNative' if platform.architecture()[0] == '32bit' else 'System32',
    'WindowsPowerShell', 'v1.0', 'powershell.exe')
python 2022/1/1 18:32:12 有224人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶