我正在尝试从Python在Windows Powershell中运行命令:
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"'])
但是,当sys.stdout.write()
使用UTF-16编码创建文件时(否则它会到处都有空格和兼容性问题),我会收到以下消息:
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\
一切都是我想要的,除了一件事:最后的InstallLocation
字符串在文本文件中被分成两行(在“PIM”处)。你知道吗
有没有办法避免这种情况发生?你知道吗
Commandline syntax to prevent wrapping in PowerShell output file?可能重复。(感谢Ansgar Wiechers在评论中回答了这个问题。)
相关问题 更多 >
编程相关推荐