silent failure pwsh -c "{hi"
See original GitHub issueSteps to reproduce
PS> pwsh -c '{hi'
PS> pwsh -c '}hi'
ParserError:
Line |
1 | }hi
| ~
| Unexpected token '}' in expression or statement.
PS>
Expected behavior
I expect both pwsh invocations to report an error.
Actual behavior
The first pwsh invocation exits with failure status but doesn’t report any error.
Environment data
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
trying to run powershell script silently failing
I tried set-executionpolicy remotesigned at the PS prompt. This script is run at the windows command prompt like this: powershell "powershell.
Read more >about Pwsh - PowerShell
Explains how to use the `pwsh` command-line interface. Displays the command-line parameters and describes the syntax.
Read more >about Preference Variables - PowerShell
PowerShell includes a set of variables that enable you to customize its behavior. These preference variables work like the options in ...
Read more >I can't get /silent to work correctly - Forums - Scooter Software
I am trying to use the /silent switch and failing spectacularly. No matter what I do, ... I have tried from cmd, Powershell,...
Read more >How to use Start-Process in PowerShell
To run the MSI silently we will need to supply the arguments /quiet or /qn and we probably don't want to restart as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try:
@iSazonov, no, it’s not related to quoting (argument parsing); what the CLI sees verbatim as the
-c
argument after argument parsing in this case is{hi
, which it parses and executes as PowerShell code, which should therefore result in a syntax (parser) error, just like withInvoke-Expression '{hi'
As @felix9’s counter example in the OP implies, the problem must be related to parsing something as a script block, given that something that doesn’t look like a script block, such as
pwsh -c '}hi'
, properly reports a syntax error.Pragmatically speaking, something like
pwsh -c '{get-date}'
doesn’t make sense, because the script block is merely created, not executed, causing its verbatim contents to be merely echoed, but the problem also occurs when you prepend&
to effect execution:As an aside: Of course, even
pwsh -c '& {get-date}'
is unnecessary, given that there’s never a need to construct a script block explicitly, given that the whole-c
argument is implicitly a script block (pwsh -c 'get-date'
will do).