Repository navigation
powershell.exe -Command parameter should handle quotes consistently across hosts and platforms #1583
Copy link
Copy link
Closed
Labels
Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Interactive-Consolethe console experiencethe console experience
Description
Steps to reproduce
powershell -Noprofile -Command '"[Console]::Error.Write(""""foo"""")"'Expected behavior
This is inbox windows v5.1 behavior
PS C:\> $powershell = Join-Path -Path $PsHome -ChildPath "powershell"
PS C:\> & $powershell -Noprofile -Command '"[Console]::Error.Write(""""foo"""")"'
fooPS C:\>
Actual behavior
"where are quotes around foo"?
PS /Users/vors/dev/PowerShell> $powershell = Join-Path -Path $PsHome -ChildPath "powershell"
PS /Users/vors/dev/PowerShell> & $powershell -Noprofile -Command '"[Console]::Error.Write(""""foo"""")"'
At line:1 char:24
+ [Console]::Error.Write(foo)
+ ~ Missing ')' in method call.
At line:1 char:24 + [Console]::Error.Write(foo)
+ ~~~
Unexpected token 'foo' in expression or statement.
At line:1 char:27
+ [Console]::Error.Write(foo)
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.10032.0
PSEdition PowerShellCore
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 3.0.0.0
GitCommitId v6.0.0-alpha.7
CLRVersion
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Interactive-Consolethe console experiencethe console experience
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]Command parameter should handle quotes consistently across hosts[/-][+]powershell.exe -Command parameter should handle quotes consistently across hosts and platforms[/+]TSlivede commentedon Oct 19, 2016
Well I think, this is just a consequence of #1995
If you launch powershell from bash (on linux):
powershell -Noprofile -Command '[Console]::Error.Write("foo")'powershell gets
[Console]::Error.Write("foo")as argv[3] and it works.If you launch powershell from cmd:
powershell -Noprofile -Command "[Console]::Error.Write(\"foo\")"powershell gets
[Console]::Error.Write("foo")as argv[3] ** and it works.When #1995 is fixed for window and linux
powershell -Noprofile -Command '[Console]::Error.Write("foo")'will work on window and linux from within powershell.
Therefore I think this bug can be closed, as powershell already handles arguments the same on windows and linux: It takes all arguments from
argvthat follow after-Command, puts spaces in between and executes the command.** (after commandline is splitted via
CommandLineToArgvWor[System.Environment]::GetCommandLineArgs()or whatever powershell uses...)joeyaiello commentedon May 23, 2017
This is my current repro (still different from 5.1, but at least with the quotes still there):
TSlivede commentedon May 23, 2017
I hope that this will soon be simplified, but the correct usage is currently:
(If the RFC gets accepted, the backslashes are no longer necessary and must be removed.)
If you want to be safe, you could use
--%microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.