Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #10677 - Update notes on redirection of native commands #10679

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can use the following methods to redirect output:

For more information about streams, see [about_Output_Streams][04].

### Redirectable output streams
## Redirectable output streams

PowerShell supports redirection of the following output streams.

Expand All @@ -54,7 +54,7 @@ redirection.
> streams of other shells. However, stdin isn't connected to the PowerShell
> pipeline for input.

### PowerShell redirection operators
## PowerShell redirection operators

The PowerShell redirection operators are as follows, where `n` represents
the stream number. The **Success** stream ( `1` ) is the default if no stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can use the following methods to redirect output:

For more information about streams, see [about_Output_Streams][04].

### Redirectable output streams
## Redirectable output streams

PowerShell supports redirection of the following output streams.

Expand All @@ -54,7 +54,7 @@ redirection.
> streams of other shells. However, stdin isn't connected to the PowerShell
> pipeline for input.

### PowerShell redirection operators
## PowerShell redirection operators

The PowerShell redirection operators are as follows, where `n` represents
the stream number. The **Success** stream ( `1` ) is the default if no stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You can use the following methods to redirect output:

For more information about streams, see [about_Output_Streams][04].

### Redirectable output streams
## Redirectable output streams

PowerShell supports redirection of the following output streams.

Expand All @@ -54,7 +54,7 @@ redirection.
> streams of other shells. However, stdin isn't connected to the PowerShell
> pipeline for input.

### PowerShell redirection operators
## PowerShell redirection operators

The PowerShell redirection operators are as follows, where `n` represents
the stream number. The **Success** stream ( `1` ) is the default if no stream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains how to redirect output from PowerShell to text files.
Locale: en-US
ms.date: 09/29/2023
ms.date: 11/29/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Redirection
Expand All @@ -26,13 +26,15 @@ You can use the following methods to redirect output:
- Use the `Tee-Object` cmdlet, which sends command output to a text file and
then sends it to the pipeline.

- Use the PowerShell redirection operators. Using the redirection operator with
a file target is functionally equivalent to piping to `Out-File` with no
extra parameters.
- Use the PowerShell redirection operators. Redirecting the output of a
PowerShell command (cmdlet, function, script) using the redirection operator
(`>`) is functionally equivalent to piping to `Out-File` with no extra
parameters. PowerShell 7.4 changed the behavior of the redirection operator
when used to redirect the **stdout** stream of a native command.

For more information about streams, see [about_Output_Streams][04].

### Redirectable output streams
## Redirectable output streams

PowerShell supports redirection of the following output streams.

Expand All @@ -54,7 +56,7 @@ redirection.
> streams of other shells. However, stdin isn't connected to the PowerShell
> pipeline for input.

### PowerShell redirection operators
## PowerShell redirection operators

The PowerShell redirection operators are as follows, where `n` represents
the stream number. The **Success** stream ( `1` ) is the default if no stream
Expand All @@ -70,6 +72,15 @@ is specified.
> Unlike some Unix shells, you can only redirect other streams to the
> **Success** stream.

## Redirecting output from native commands

PowerShell 7.4 changed the behavior of the redirection operators when used to
redirect the **stdout** stream of a native command. PowerShell 7.4 changed the
behavior. The redirection operators now preserve the byte-stream data when
redirecting output from a native command. PowerShell doesn't interpret the
redirected data or add any additional formatting. For more information, see
[Example #7](#example-7-redirecting-binary-data-from-a-native-command).

## Examples

### Example 1: Redirect errors and output to a file
Expand Down
11 changes: 7 additions & 4 deletions reference/7.4/Microsoft.PowerShell.Utility/Out-File.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Utility
ms.date: 07/27/2023
ms.date: 11/29/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Out-File
Expand Down Expand Up @@ -34,9 +34,12 @@ Out-File [[-Encoding] <Encoding>] -LiteralPath <string> [-Append] [-Force] [-NoC
The `Out-File` cmdlet sends output to a file. It implicitly uses PowerShell's formatting system to
write to the file. The file receives the same display representation as the terminal. This means
that the output may not be ideal for programmatic processing unless all input objects are strings.
When you need to specify parameters for the output, use `Out-File` rather than the redirection
operator (`>`). For more information about redirection, see
[about_Redirection](../Microsoft.PowerShell.Core/About/about_Redirection.md).

When you use the redirection operator (`>`) to redirect output to a file, internally, PowerShell
adds `Out-File` to the end of the pipeline. If you need to change how PowerShell writes to the file,
use `Out-File` with parameters rather than the redirection operator (`>`). PowerShell 7.4 also
changed the behavior when redirecting from a native command. For more information about redirection,
see [about_Redirection](../Microsoft.PowerShell.Core/About/about_Redirection.md).

## EXAMPLES

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: What's New in PowerShell 7.4
description: New features and changes released in PowerShell 7.4
ms.date: 11/16/2023
ms.date: 11/29/2023
---

# What's New in PowerShell 7.4
Expand All @@ -21,6 +21,14 @@ For a complete list of changes, see the [CHANGELOG][15] in the GitHub repository
- `Test-Json` now uses Json.Schema.Net instead of Newtonsoft.Json.Schema. With this change,
`Test-Json` no longer supports the older Draft 4 schemas. ([#18141][18141]) (Thanks @gregsdennis!)
- Output from `Test-Connection` now includes more detailed information about TCP connection tests
- .NET introduced changes that affected `Test-Connection`. The cmdlet now returns error about the
need to use `sudo` on Linux platforms when using a custom buffer size ([#20369][20369])
sdwheeler marked this conversation as resolved.
Show resolved Hide resolved
- Experimental feature [PSNativeCommandPreserveBytePipe][10] is now mainstream. PowerShell now
preserves the byte-stream data when redirecting the **stdout** stream of a native command to a
file or when piping byte-stream data to the stdin stream of a native command.
- Change how relative paths in `Resolve-Path` are handled when using the **RelativeBasePath**
parameter ([#19755][19755]) (Thanks @MartinGC94!)
- Remove unused PSv2 code - removes TabExpansion function ([#18337][18337])

## Installer updates

Expand Down Expand Up @@ -228,6 +236,7 @@ For more information about the Experimental Features, see [Using Experimental Fe
[13]: /powershell/module/psreadline
[14]: /powershell/module/microsoft.powershell.psresourceget
[15]: https://github.com/PowerShell/PowerShell/blob/master/CHANGELOG/preview.md

[14953]: https://github.com/PowerShell/PowerShell/pull/14953
[17191]: https://github.com/PowerShell/PowerShell/pull/17191
[17654]: https://github.com/PowerShell/PowerShell/pull/17654
Expand All @@ -240,6 +249,7 @@ For more information about the Experimental Features, see [Using Experimental Fe
[17907]: https://github.com/PowerShell/PowerShell/pull/17907
[17938]: https://github.com/PowerShell/PowerShell/pull/17938
[17948]: https://github.com/PowerShell/PowerShell/pull/17948
[17955]: https://github.com/PowerShell/PowerShell/pull/17955
[18030]: https://github.com/PowerShell/PowerShell/pull/18030
[18130]: https://github.com/PowerShell/PowerShell/pull/18130
[18138]: https://github.com/PowerShell/PowerShell/pull/18138
Expand All @@ -248,6 +258,7 @@ For more information about the Experimental Features, see [Using Experimental Fe
[18222]: https://github.com/PowerShell/PowerShell/pull/18222
[18261]: https://github.com/PowerShell/PowerShell/pull/18261
[18308]: https://github.com/PowerShell/PowerShell/pull/18308
[18337]: https://github.com/PowerShell/PowerShell/pull/18337
[18351]: https://github.com/PowerShell/PowerShell/pull/18351
[18355]: https://github.com/PowerShell/PowerShell/pull/18355
[18474]: https://github.com/PowerShell/PowerShell/pull/18474
Expand Down Expand Up @@ -314,14 +325,14 @@ For more information about the Experimental Features, see [Using Experimental Fe
[19601]: https://github.com/PowerShell/PowerShell/pull/19601
[19616]: https://github.com/PowerShell/PowerShell/pull/19616
[19622]: https://github.com/PowerShell/PowerShell/pull/19622
[19683]: https://github.com/PowerShell/PowerShell/pull/19683
[19715]: https://github.com/PowerShell/PowerShell/pull/19715
[19740]: https://github.com/PowerShell/PowerShell/pull/19740
[19755]: https://github.com/PowerShell/PowerShell/pull/19755
[19765]: https://github.com/PowerShell/PowerShell/pull/19765
[19814]: https://github.com/PowerShell/PowerShell/pull/19814
[19819]: https://github.com/PowerShell/PowerShell/pull/19819
[19831]: https://github.com/PowerShell/PowerShell/pull/19831
[19683]: https://github.com/PowerShell/PowerShell/pull/19683
[19824]: https://github.com/PowerShell/PowerShell/pull/19824
[19831]: https://github.com/PowerShell/PowerShell/pull/19831
[20369]: https://github.com/PowerShell/PowerShell/pull/20369
[20371]: https://github.com/PowerShell/PowerShell/pull/20371
[17955]: https://github.com/PowerShell/PowerShell/pull/17955