PowershellGenerated文本文件将行拆分为多个部分

2024-04-23 20:29:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从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”处)。你知道吗

有没有办法避免这种情况发生?你知道吗


Tags: windowssyssoftwarepublisherflashadobesubprocessplayer