Powershell生成的文本文件拆分部件中的行

时间:2017-08-04 23:04:05

标签: python powershell text

我试图从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"'])

然而,在使用UTF-16编码的sys.stdout.write() - 创建的文件时(否则它在整个地方都有空格和兼容性问题),我受到以下欢迎:

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")。

有没有办法避免这种情况发生?

1 个答案:

答案 0 :(得分:0)

Commandline syntax to prevent wrapping in PowerShell output file?可能重复。 (感谢Ansgar Wiechers在评论中回答这个问题。)