从Python调用PowerShell脚本

从Python调用PowerShell脚本,第1张

从Python调用PowerShell脚本

首先,

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

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

psxmlgen = subprocess.Popen([r'C:WINDOWSsystem32WindowsPowerShellv1.0powershell.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')


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5487376.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存