首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我会得到这个错误,如何绕过它呢?(powershell & python)

为什么我会得到这个错误,如何绕过它呢?(powershell & python)
EN

Stack Overflow用户
提问于 2022-09-20 09:06:24
回答 1查看 61关注 0票数 1

我有许多带有多个参数的其他命令,但是python似乎不喜欢这个命令。任何帮助都将不胜感激。该命令在powershell中没有问题。我试着用',",‘“的各种组合来让它起作用

代码语言:javascript
运行
复制
'''subprocess.run("""powershell.exe Get-Service -Name 'Remote Desktop Services' ""Remote Desktop Configuration"", 'Remote Desktop Services UserMode Port Redirector'""", shell=True, text=True)'''

在地狱中工作的命令

代码语言:javascript
运行
复制
''' Get-Service -Name "Remote Desktop Services", "Remote Desktop Configuration", "Remote Desktop Services UserMode Port Redirector"'''

输出

代码语言:javascript
运行
复制
'''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

EN

回答 1

Stack Overflow用户

发布于 2022-09-20 09:59:03

代码语言:javascript
运行
复制
def run(self, cmd):
    completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
    return completed

这应该能胜任这项工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73784180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档