Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PSHostUserInterface and Windows 10/PowerShell 5.0

$
0
0

Hello,

we're currently working on an application that hosts a PowerShell runspace/pipeline and executes PowerShell scripts. Now there's something my colleague and I noticed which we can't explain.

The PSHostUserInterface interface exposes different methods to write console output to, specifically in this case Write(ConsoleColor, ConsoleColor, String), Write(String) as well asWriteLine(ConsoleColor, ConsoleColor, String), WriteLine(String) andWriteLine().

These methods are called as soon as a script writes something to the PowerShell host, for example a simpleWrite-Host "Hello World!". Now the problem here is that our code behaves differently while running unit tests on my and my colleague's PC. The difference seems to be that I recently upgraded to Windows 10 (PowerShell 5.0) while he's still running Windows 8.1 (PowerShell 4.0). (This is just what we think is the cause, it could be something else though). The project runs with .NET 4.5.1

They behave the following way:

Windows 8.1 (PowerShell 4.0)

Write-Host "Hello World!" -> Calls/triggers Write(ConsoleColor, ConsoleColor, String) with the for-/backgroundcolor and the string value (Hello World!) first and thenWriteLine(ConsoleColor, ConsoleColor, String) with the colors and empty string value, which should represent a newline.

Write-Host "Hello World! -NoNewLine -> Calls/triggers Write(ConsoleColor, ConsoleColor, String) with the for-/backgroundcolor and the string value (Hello World!) only.

Windows 10 (PowerShell 5.0)

Write-Host "Hello World!" -> Calls/triggers WriteLine(ConsoleColor, ConsoleColor, String) with the for-/backgroundcolor and the string value (Hello World!) only. There's also no appended newline.

Write-Host "Hello World!" -NoNewLine -> Calls/triggers WriteLine(ConsoleColor, ConsoleColor, String) with the for-/backgroundcolor and the string value (Hello World!) only. Also no newline here (which shouldn't be of course).

----

That is the basic problem. It seems like under Windows 8.1 the framework is executing and triggering the right methods for the Write-Host cmdlet but it's different with Windows 10/PowerShell 5.0. We're just talking about carriage returns, but when writing the output to a list and using that list for further processing, I'm sure most of you can imagine that this is a problem.

Does anyone has experienced the same behavior? Is this a bug in the new PowerShell? Why is this happening?


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>