在python中的子进程中使用的Get-ACL命令中的注册表名称中使用括号时会出错

时间:2017-01-02 19:19:25

标签: python powershell subprocess parentheses

ps_cmdlet = r'Get-Acl -Path "HKLM:\SOFTWARE\{ab}" | Format-List'

p = subprocess.call(['powershell', '-Command', '& {'+ps_cmdlet+'}'],shell=True)

我收到以下错误

Get-Acl : Cannot find path 'HKLM:\SOFTWARE\{ab}' because it does not exist.
At line:1 char:4
+ & {Get-Acl -Path "HKLM:\SOFTWARE\{ab}" | Format-List}
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
    + FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand

1 个答案:

答案 0 :(得分:1)

用反引号转义括号:

ps_cmdlet = r'Get-Acl -Path "HKLM:\SOFTWARE\`{ab`}" | Format-List'
相关问题