-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Updated later to include the problem with embedded double quotes.
Steps to reproduce
Embedded whitespace:
'"Hi!"' > './t 1.ps1'; Start-Process -Wait -NoNewWindow pwsh -ArgumentList '-noprofile', '-file', './t 1.ps1'Embedded double quotes:
Start-Process -Wait -NoNewWindow pwsh -ArgumentList '-noprofile', '-command', '"Hi!"'Expected behavior
In both cases:
Hi!
That is, script file ./t 1.ps1 should execute, and double-quoted string literal "Hi!" should print.
Actual behavior
Embedded whitespace:
Invocation fails, because the ./t 1.ps1 is passed as two arguments:
The argument './t' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
The only way to make this currently work is to embed (potentially escaped) double quotes: '"./t 1.ps1"' or "`"./t 1.ps1`""; e.g.:
Start-Process -Wait -NoNewWindow pwsh -ArgumentList '-noprofile', '-file', "`"./t 1.ps1`""Update: Overall, the best workaround is to pass a single string containing all arguments to -ArgumentList and use embedded quoting and escaping as necessary:
Start-Process -Wait -NoNewWindow pwsh -ArgumentList '-noprofile -file "./t 1.ps1"'Embedded double quotes:
The embedded double quotes are unexpectedly removed.
The only way to make this currently work is to \-escape the embedded double quotes:
Start-Process -Wait -NoNewWindow pwsh -ArgumentList '-noprofile', '-command', '\"Hi!\"'Update: Again, the best workaround is to use a single string:
Start-Process -Wait -NoNewWindow pwsh -ArgumentList '-noprofile -command \"Hi!\"'Environment data
PowerShell Core v6.0.0-rc (v6.0.0-rc) on Microsoft Windows 7 Enterprise (64-bit; v6.1.7601)
Windows PowerShell v5.1.14409.1012 on Microsoft Windows 7 Enterprise (64-bit; v6.1.7601)