I tried calling the PowerShell command from Python as follows, but the return value was only displayed on the screen, but I could not receive it from Python.
importos
os.system("powerershell-Command Get-ItemProperty HKLM:SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*^|Select-Object DisplayName^|Format-Table –AutoSize")
How can I pass the data to Python after outputting the PowerShell output to a text file?
python windows powershell
In addition to the comments, the following article is simply described:
Run Windows commands in Python's subprocess
Call Commands from Python (Windows Edition)
If you apply it, you can do it as follows.
import subprocess
res=subprocess.run("powershell-Command Get-ItemProperty HKLM:SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*^|Select-Object DisplayName^|Format-Table–AutoSize",
stdout=subprocess.PIPE, shell=True, encoding="cp932")
print(res.stdout)
© 2024 OneMinuteCode. All rights reserved.