LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

JKI.Net with powershell - strange result characters

Solved!
Go to solution

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

 

Status Name DisplayName
------ ---- -----------
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

 

0 Kudos
Message 1 of 4
(935 Views)

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.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 4
(922 Views)

Ahhh, ANSI escape characters, the bane of ancient chat rooms.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 4
(879 Views)
Solution
Accepted by topic author joernheit

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

0 Kudos
Message 4 of 4
(853 Views)