【发布时间】:2018-06-26 20:53:44
【问题描述】:
我一直在尝试以下方法:
process=check_output(["powershell.exe", "Get-Childitem C:\\Windows\\*.log"]);
return process
它返回一个输出:
b'\r\n\r\n 目录:C:\Windows\r\n\r\n\r\nMode LastWriteTime Leng 名称 \r\n---- ------------- - ----- ---- \r\n-a---- 2018 年 6 月 14 日上午 11:26 4056 DtcInstall.log \r\n-a---- 2018 年 6 月 21 日上午 11:33 41261 iis.log \r\n-a---- 9/12/2016 4:34 AM 1342 lsasetup.log \r\n-a---- 6/25/2018 12:06 PM 8904 PFRO.log \r\n-a---- 6/21/2018 12: 04 PM 7530 setupact.log \r\n-a---- 9/12/2016 凌晨 4:35 0 setuperr.log \r\n-a---- 6/26/201 8 12:17 PM 275 WindowsUpdate.log \r\n\r\n\r\n'
到处都是 \n 和 \r。如何让它以所需的标准格式返回?我还尝试了使用 .PIPE 的子进程 Popen 方法,它给出了相同的结果。
【问题讨论】:
-
您可以尝试:
process=check_output(["powershell.exe", "Get-Childitem C:\\Windows\\*.log"]).strip();或按此处所述逐行解析输出:stackoverflow.com/questions/36422572/…
标签: python powershell subprocess