question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

silent failure pwsh -c "{hi"

See original GitHub issue

Steps 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
doctordnscommented, Nov 29, 2020

Try:

pwsh -c "'}hi'"
0reactions
mklement0commented, Nov 29, 2020

@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:

# Equally broken: also fails silently
pwsh -c '& {get-date'

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found