我有许多带有多个参数的其他命令,但是python似乎不喜欢这个命令。任何帮助都将不胜感激。该命令在powershell中没有问题。我试着用',",‘“的各种组合来让它起作用
'''subprocess.run("""powershell.exe Get-Service -Name 'Remote Desktop Services' ""Remote Desktop Configuration"", 'Remote Desktop Services UserMode Port Redirector'""", shell=True, text=True)'''
在地狱中工作的命令
''' Get-Service -Name "Remote Desktop Services", "Remote Desktop Configuration", "Remote Desktop Services UserMode Port Redirector"'''
输出
'''Get-Service : A positional parameter cannot be found that accepts argument 'Desktop'. At line:1 char:1 + Get-Service -Name 'Remote Desktop Services', Remote Desktop Configura +
Microsoft.PowerShell.Commands.GetServiceCommand‘’CategoryInfo : InvalidArgument:(:) Get-Service,ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound
发布于 2022-09-20 09:59:03
def run(self, cmd):
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
return completed
这应该能胜任这项工作
https://stackoverflow.com/questions/73784180
复制相似问题