-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
According to about_Redirection:
Using the redirection operator with a file target is functionally equivalent to piping to Out-File with no extra parameters.
The documentation for Out-File -NoNewLine says:
No newline is added after the last output string.
Which means Out-File does normally add a newline. And this is what you see in PowerShell 7.3.10. If the output does not end in a newline, Out-File and file redirection add a newline. But in PowerShell 7.4.0, with file redirection that newline is no longer added.
To make this easy to repro you'll want a native executable that outputs character data but no newline (LF or CR/LF) at the end. Here's a C# program that does that. You don't have to use this program to repro the problem. It just helps.
namespace Example;
internal class Program
{
static void Main()
{
Console.Write("Hello"); // Note that it's not WriteLine()
}
}
This appears to be related to the PR: #17857 by @SeeminglyScience that was added in preview 4
Appears to be related to #20747 and #20808.
Expected behavior
# See "Steps to reproduce" for source code for Hello.exe
PS> .\Hello.exe >x.txt
PS> (Get-Content x.txt -Raw).EndsWith([System.Environment]::NewLine)
TrueActual behavior
# See "Steps to reproduce" for source code for Hello.exe
PS> .\Hello.exe >x.txt
PS> (Get-Content x.txt -Raw).EndsWith([System.Environment]::NewLine)
FalseError details
N/AEnvironment data
Name Value
---- -----
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
