01-12-2022 05:44 AM - edited 01-12-2022 05:47 AM
I am using LabVIEW 2016 and the JKI.Net library to access powershell 7 and using powershell calls according the example in ..\vi.lib\JKI\JKI DotNet System Exec\examples\example_powershell.vi.
The command line call is "C:\Program Files\PowerShell\7\pwsh.exe" instead of the default 'powershell.exe' to reference the new ps 7.
This worked all well until I updatet powershell from 7.1.1 to 7.21.
Since than I receive some strange characters in the resulting string in the standard output when I use some powershll commands (but not with all powershell commands).
The examples default powershell call works as before. If I extend the call by another line for e.g.
Get-Service 'Win*'
than in the std out indicator some characters appear which does not appear in the standard powershell console which I used for comparison
[32;1mStatus Name DisplayName[0m
[32;1m------ ---- -----------[0m
Running WinDefend Microsoft Defender Antivirus-Dienst
Running WinHttpAutoProxyS. WinHTTP-Web Proxy Auto-Discovery-Dien.
Does anybody know the reason behind this behaviour or can reproduce it. I am pretty sure this started after ps update to 7.2.1.
Jörn
Solved! Go to Solution.
01-12-2022 06:01 AM
Those are text formatting escape sequences, a very old technique to format text used when video terminals where in character mode.
See for example, https://en.wikipedia.org/wiki/ANSI_escape_code , section Color. In your example, sequences are used to set text to green and then to default color again.
That said, I don't know how to disable them. Maybe it depends on a video terminal emulation setting. Or maybe it's possible to disable formatting.
01-12-2022 09:37 AM
Ahhh, ANSI escape characters, the bane of ancient chat rooms.
01-13-2022 02:30 AM
Thanks for pointing in that direction Paolo.
Indeed we can read at the MS release notes for Powershell 7.2.1 that the experimental feature 'PSAnsiRendering' was turned into mainstream with this release and under about_ANSI_Terminals further description gives the capability to have the output as 'PlainText'
$PSStyle.OutputRendering = 'PlainText'
and back to 'ANSI' with
$PSStyle.OutputRendering = 'ANSI'
Tested and confirmed. I simply execute this as the first command with JKI.NET and powershell. As an alternative changing the PS profile is an option.
Jörn