I'm trying to run a command in Windows Powershell from Python:
import subprocess, os, sys
subprocess.check_call(['powershell.exe', 'Get-ItemProperty HKLM:/Software/Wow6432Node/Microsoft/Windows/CurrentVersion/Uninstall/* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, InstallLocation > "C:/Program Files/softwarelist.txt"'])
However, upon sys.stdout.write()
-ing the created file with UTF-16 encoding (otherwise it has spaces and compatibility issues all over the place), I am greeted with the following:
DisplayName : Adobe Flash Player 26 NPAPI
DisplayVersion : 26.0.0.137
Publisher : Adobe Systems Incorporated
InstallDate :
InstallLocation :
DisplayName : Adobe Flash Player 26 PPAPI
DisplayVersion : 26.0.0.137
Publisher : Adobe Systems Incorporated
InstallDate :
InstallLocation :
DisplayName : Agenda At Once 3.3.3
DisplayVersion : 3.3.3
Publisher : Dataland Software
InstallDate : 20161106
InstallLocation : E:\Applications for Work\PIM and Projects\Agenda at Once
PIM\Agenda at Once Components\Agenda At Once\
Everything is as I want it to be, except for one thing: that last InstallLocation
string is split into two lines (at the "PIM") in the text file.
Is there a way to avoid this happening?