开发者

PowerShell removing console message colors when using tee-object

开发者 https://www.devze.com 2023-01-08 02:43 出处:网络
Is there any way to stop PowerShell from removing console message colors when using tee-object? When I run without tee-object I get the nice error and verbose powershell message colors like this:

Is there any way to stop PowerShell from removing console message colors when using tee-object?

When I run without tee-object I get the nice error and verbose powershell message colors like this:

powershell.exe -noprofile -file $project_root/test_main.ps1

PowerShell removing console message colors when using tee-object

However, when I'm using tee-object (b/c I want logging to console & file), the message color开发者_JAVA百科s are not shown on the console (I know the file won't show it) like this:

powershell.exe -noprofile -file $project_root/test_main.ps1 | tee-object -FilePath $log

PowerShell removing console message colors when using tee-object

If powershell is just using tee-object to split the output to a file in addition to the console, why am I losing the console formatting?


Try this instead:

powershell.exe -noprofile -command { $path\test_main.ps1 | tee-object $log }

This happens because this part is executed first:

powershell.exe -noprofile -file $project_root/test_main.ps1 

Such that what tee-object sees is the output of a native EXE. And AFAICT, PowerShell doesn't output error records (or highlight) stderr output from a native EXE (unless you redirect the error stream e.g. 2>err.log.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号