From b0480e2b412949a7e349e10ff50dfc084aaeff6d Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Thu, 18 Aug 2022 13:52:59 -0500 Subject: [PATCH] Add note about passing quoted strings to cmd --- .../About/about_Parsing.md | 22 ++++++++++++++++++- .../About/about_Parsing.md | 22 ++++++++++++++++++- .../About/about_Parsing.md | 22 ++++++++++++++++++- .../About/about_Parsing.md | 22 ++++++++++++++++++- 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/reference/5.1/Microsoft.PowerShell.Core/About/about_Parsing.md b/reference/5.1/Microsoft.PowerShell.Core/About/about_Parsing.md index 0e8c79ef2b4f..60da81153345 100644 --- a/reference/5.1/Microsoft.PowerShell.Core/About/about_Parsing.md +++ b/reference/5.1/Microsoft.PowerShell.Core/About/about_Parsing.md @@ -1,7 +1,7 @@ --- description: Describes how PowerShell parses commands. Locale: en-US -ms.date: 05/17/2022 +ms.date: 08/18/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Parsing @@ -240,6 +240,26 @@ variable the token is passed through as-is. You cannot use stream redirection (like `>file.txt`) because they are passed verbatim as arguments to the target command. +Using the stop-parsing token is also the best way to ensure that quoted strings +that are passed as parameters to `cmd.exe` or Windows batch (`.cmd` or `.bat`) +files are handled properly. + +In the following example, the first step runs a command without using the +stop-parsing token. PowerShell evaluates the quoted string and passes the value +(without quotes) to `cmd.exe`, which results in an error. + +```powershell +PS> cmd /c echo "a|b" +'b' is not recognized as an internal or external command, +operable program or batch file. +PS> cmd /c --% echo "a|b" +"a|b" +``` + +> [!NOTE] +> Some commands on Windows systems are implemented as a Windows batch file. For +> example, that `az` command for Azure CLI is a Windows batch file. + ### Passing arguments that contain quote characters Some native commands expect arguments that contain quote characters. Normally, diff --git a/reference/7.0/Microsoft.PowerShell.Core/About/about_Parsing.md b/reference/7.0/Microsoft.PowerShell.Core/About/about_Parsing.md index 33f63d8e2581..8ff267811158 100644 --- a/reference/7.0/Microsoft.PowerShell.Core/About/about_Parsing.md +++ b/reference/7.0/Microsoft.PowerShell.Core/About/about_Parsing.md @@ -1,7 +1,7 @@ --- description: Describes how PowerShell parses commands. Locale: en-US -ms.date: 05/17/2022 +ms.date: 08/18/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Parsing @@ -240,6 +240,26 @@ variable the token is passed through as-is. You cannot use stream redirection (like `>file.txt`) because they are passed verbatim as arguments to the target command. +Using the stop-parsing token is also the best way to ensure that quoted strings +that are passed as parameters to `cmd.exe` or Windows batch (`.cmd` or `.bat`) +files are handled properly. + +In the following example, the first step runs a command without using the +stop-parsing token. PowerShell evaluates the quoted string and passes the value +(without quotes) to `cmd.exe`, which results in an error. + +```powershell +PS> cmd /c echo "a|b" +'b' is not recognized as an internal or external command, +operable program or batch file. +PS> cmd /c --% echo "a|b" +"a|b" +``` + +> [!NOTE] +> Some commands on Windows systems are implemented as a Windows batch file. For +> example, that `az` command for Azure CLI is a Windows batch file. + ### Passing arguments that contain quote characters Some native commands expect arguments that contain quote characters. Normally, diff --git a/reference/7.2/Microsoft.PowerShell.Core/About/about_Parsing.md b/reference/7.2/Microsoft.PowerShell.Core/About/about_Parsing.md index eb31d8591c6e..b3f8fd514205 100644 --- a/reference/7.2/Microsoft.PowerShell.Core/About/about_Parsing.md +++ b/reference/7.2/Microsoft.PowerShell.Core/About/about_Parsing.md @@ -1,7 +1,7 @@ --- description: Describes how PowerShell parses commands. Locale: en-US -ms.date: 05/17/2022 +ms.date: 08/18/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Parsing @@ -240,6 +240,26 @@ variable the token is passed through as-is. You cannot use stream redirection (like `>file.txt`) because they are passed verbatim as arguments to the target command. +Using the stop-parsing token is also the best way to ensure that quoted strings +that are passed as parameters to `cmd.exe` or Windows batch (`.cmd` or `.bat`) +files are handled properly. + +In the following example, the first step runs a command without using the +stop-parsing token. PowerShell evaluates the quoted string and passes the value +(without quotes) to `cmd.exe`, which results in an error. + +```powershell +PS> cmd /c echo "a|b" +'b' is not recognized as an internal or external command, +operable program or batch file. +PS> cmd /c --% echo "a|b" +"a|b" +``` + +> [!NOTE] +> Some commands on Windows systems are implemented as a Windows batch file. For +> example, that `az` command for Azure CLI is a Windows batch file. + ### Passing arguments that contain quote characters Some native commands expect arguments that contain quote characters. Normally, diff --git a/reference/7.3/Microsoft.PowerShell.Core/About/about_Parsing.md b/reference/7.3/Microsoft.PowerShell.Core/About/about_Parsing.md index be1b4ec1981e..6920d8b96c02 100644 --- a/reference/7.3/Microsoft.PowerShell.Core/About/about_Parsing.md +++ b/reference/7.3/Microsoft.PowerShell.Core/About/about_Parsing.md @@ -1,7 +1,7 @@ --- description: Describes how PowerShell parses commands. Locale: en-US -ms.date: 05/17/2022 +ms.date: 08/18/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 title: about Parsing @@ -240,6 +240,26 @@ variable the token is passed through as-is. You cannot use stream redirection (like `>file.txt`) because they are passed verbatim as arguments to the target command. +Using the stop-parsing token is also the best way to ensure that quoted strings +that are passed as parameters to `cmd.exe` or Windows batch (`.cmd` or `.bat`) +files are handled properly. + +In the following example, the first step runs a command without using the +stop-parsing token. PowerShell evaluates the quoted string and passes the value +(without quotes) to `cmd.exe`, which results in an error. + +```powershell +PS> cmd /c echo "a|b" +'b' is not recognized as an internal or external command, +operable program or batch file. +PS> cmd /c --% echo "a|b" +"a|b" +``` + +> [!NOTE] +> Some commands on Windows systems are implemented as a Windows batch file. For +> example, that `az` command for Azure CLI is a Windows batch file. + ### Passing arguments that contain quote characters Some native commands expect arguments that contain quote characters. Normally,