Answer the question
In order to leave comments, you need to log in
How to send commands from Python to PowerShell line by line?
Since I'm still not a chipper in Python and in programming, a detail has surfaced that I have to study. Based on my previous question ( https://toster.ru/q/371771), I got into PowerShell and was able to turn down the screen brightness with 2 simple commands.
$monitor=Get-WmiObject -Namespace root/WMI -ClassName WmiMonitorBrightnessMethods
$monitor.WmiSetBrightness(0,50)
import subprocess
proc = subprocess.Popen(['powershell', '$monitor=Get-WmiObject -Namespace root/WMI -ClassName WmiMonitorBrightnessMethods', '$monitor.WmiSetBrightness(0,50)'])
proc.wait()
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Answer the question
In order to leave comments, you need to log in
As you have already written. Between PS commands you need ";" .
Replace:
on the:
The final code in this case:
import subprocess
proc = subprocess.Popen(['powershell', '$monitor=Get-WmiObject -Namespace root/WMI -ClassName WmiMonitorBrightnessMethods; $monitor.WmiSetBrightness(0,50)'])
proc.wait()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question