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.

Using -Args with -Command does not work as documented

See original GitHub issue

The powershell command line docs suggest that the “-Command” option may be used with the “-args” option to pass extra arguments to a script block. However, this does not work as described.

Recommend updating the command line documentation to document the actual behavior of -Command, which does not support an -args option.

Usage: pwsh[.exe] [-Login] [[-File] <filePath> [args]]
                  [-Command { - | <script-block> [-args <arg-array>]
                                | <string> [<CommandParameters>] } ]

Steps to reproduce

powershell.exe -Command "{ echo $args[1] }" -args one two three

Expected behavior

print two

Actual behavior

error:

aaronla@aaronla-r:scratch$ dotnet pwsh -command "{ echo $args[1] }" -args one two three
ParserError:
Line |
   1 |  { echo $args[1] } -args one two three
     |                    ~~~~~
     | Unexpected token '-args' in expression or statement.

Environment data

aaronla@aaronla-r:PowerApps-CoreServices$ dotnet pwsh -command echo $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.19043
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:closed
  • Created 2 years ago
  • Comments:18

github_iconTop GitHub Comments

1reaction
ghostcommented, May 18, 2021

Thanks for clarifying @rjmholt. The docs make it seem like it’s a command line argument, but now I see what you mean – it’s more intended as a powershell function argument to be used from within powershell, and not to be used at the command line / StartProcess / exec.

0reactions
rjmholtcommented, May 17, 2021

Given the discussion in the issue, I think the docs already cover this case and have marked it resolved. If there are changes you’d like to see in the documentation, please open an issue in https://github.com/MicrosoftDocs/PowerShell-Docs.

<div> GitHub</div><div>MicrosoftDocs/PowerShell-Docs</div><div>The official PowerShell documentation sources. Contribute to MicrosoftDocs/PowerShell-Docs development by creating an account on GitHub.</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Command does not escape arguments as expected on ...
Currently the windows implementation of Command will automatically attempt to escape arguments before concatenating them into a single command ...
Read more >
How do I use the lines of a file as arguments of a command?
Documented in the bash man page in the 'Command Substitution' section. ... In my case using (Neo)Vim it does not and the args...
Read more >
kubectl run --command vs -- arguments - kubernetes
If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you...
Read more >
Define a Command and Arguments for a Container
This page shows how to define commands and arguments when you run a container in a Pod. Before you begin You need to...
Read more >
Where is the `--` (double dash) argument documented?
The intent is to document all commands that do not follow the guidelines in their POSIX man page, from POSIX chapter 12.02 third...
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