Reputation: 25
I have a bunch of other commands with multiple arguments, but python doesnt seem to like this one. Any help would be appreciated. The command runs no problem in powershell. I tried all sorts of combinations with ', ", "" to get it to work
'''subprocess.run("""powershell.exe Get-Service -Name 'Remote Desktop Services' ""Remote Desktop Configuration"", 'Remote Desktop Services UserMode Port Redirector'""", shell=True, text=True)'''
the command that works in powerhell
''' Get-Service -Name "Remote Desktop Services", "Remote Desktop Configuration", "Remote Desktop Services UserMode Port Redirector"'''
output
'''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 +
CategoryInfo : InvalidArgument: (:) [Get-Service], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetServiceCommand '''
Upvotes: 1
Views: 1375
Reputation: 329
def run(self, cmd):
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
return completed
this should do the job
Upvotes: 0