GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CLI: when installed as a .NET global tool (dotnet tool), argument parsing is broken · Issue #11747 · PowerShell/PowerShell

CLI: when installed as a .NET global tool (dotnet tool), argument parsing is broken #11747

New issue
Copy link
New issue
Copy link
Closed
#21333
Closed
CLI: when installed as a .NET global tool (dotnet tool), argument parsing is broken#11747
#21333
Copy link
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Maintainers-Buildspecific to affecting the buildspecific to affecting the build

Description

@mklement0
Michael Klement (mklement0)
opened on Jan 31, 2020
Issue body actions

Note:

  • This problem was discovered by Gerardo Grignoli (@gerardog), and this issue is meant to supersede CLI: escaped command line quotes "" difference with powershell 5.1 #11569

  • It only affects PowerShell when installed as a .NET global tool:

    • dotnet tool install --global PowerShell
    • Note: You need a .NET Core SDK 3.1 installation first.

Steps to reproduce

# NOTE: 
#  * Problem shows if `pwsh` was installed via `dotnet tool --global`
#  * Run from *cmd.exe* or *bash*
pwsh -noprofile -c "write-output 1 \"2 3\""

Expected behavior

1
2 3

That is, the escaped embedded double quotes (\") should be honored, resulting in two outputs, 1, and '2 3'.

This is indeed what happens with a regularly installed version.

Actual behavior

1
2
3

This output suggests that the embedded escaped double quotes (\") were unexpectedly eaten.

Environment data

PowerShell Core 7.0 # as a global .NET tool, all platforms
Reacted by Bo Lingen, Gennadii Saltyshchak and Friedrich von Never
Reacted by Bo Lingen
Reacted by Bo Lingen

Activity

  1. Michael Klement (mklement0)
    added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Jan 31, 2020
  2. Michael Klement (mklement0)
    changed the title [-]CLI: argument parsing when installed as a .NET global tool (dotnet tool) is broken[/-] [+]CLI: when installed as a .NET global tool (dotnet tool), argument parsing is broken[/+] on Jan 31, 2020
  3. gerardog commented on Feb 2, 2020

    @gerardog
    Gerardo Grignoli (gerardog)
    on Feb 2, 2020
    More actions

    I think I have a clue about this one:

    The Global Tool Shim is accepting the args[] as provided in the main function by .NET.

    PowerShell/src/Microsoft.PowerShell.GlobalTool.Shim/GlobalToolShim.cs

    Line 33 in 42b599d

    string argsString = args.Length > 0 ? string.Join(" ", args) : null;

    However, to keep the quotes correctly it should be using either Environment.CommandLine
    or Win32Api:
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern System.IntPtr GetCommandLine();

    Hope it helps.-

    Reacted by Michael Klement
  4. mklement0 commented on Feb 2, 2020

    @mklement0
    Michael Klement (mklement0)
    on Feb 2, 2020
    ContributorAuthor
    More actions

    Nice sleuthing, Gerardo Grignoli (@gerardog).

    The simplest and robust solution is to copy the elements of args to a ProcessStartInfo instance's ArgumentList property (a new, collection-based alternative to the single-string .Arguments property), which on Windows performs proper re-quoting and escaping as necessary, and on Unix passes the already-parsed arguments through as an array:

                // Use ProcessStartInfo.ArgumentList to robustly pass arguments through.
                var psi =  new ProcessStartInfo("dotnet");
                psi.ArgumentList.Add(pwshPath);
                foreach (var arg in args) { psi.ArgumentList.Add(arg); }
    
                if (File.Exists(pwshPath))
                {
                    var process = System.Diagnostics.Process.Start(psi);
                    process.WaitForExit();
                    
                    return process.ExitCode;
                }
  5. Rain Sallow (/u/ta11ow) (vexx32)
    added
    WG-Maintainers-Buildspecific to affecting the buildspecific to affecting the build
    Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the product
    and removed
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Mar 26, 2020
  6. gerardog commented on Apr 22, 2022

    @gerardog
    Gerardo Grignoli (gerardog)
    on Apr 22, 2022
    More actions

    which on Windows performs proper re-quoting and escaping as necessary

    Does it?

    A few edge cases:

    • Arguments without spaces wrapped in single or double quotes, will be re-quoted?
    • Arguments with spaces wrapped in single quotes, will be re-quoted in double quotes?

    Thanks

  7. mklement0 commented on Apr 22, 2022

    @mklement0
    Michael Klement (mklement0)
    on Apr 22, 2022
    ContributorAuthor
    More actions

    Does it?

    Yes, assuming the target application uses the command-line parsing rules of C/C++/.NET applications, as described here.
    That's the best that can be done - ultimately, any application is free to make up its own parsing rules.

    As for the edge cases:

    Arguments without spaces wrapped in single or double quotes, will be re-quoted?

    No - if an argument contains no spaces, it is passed unquoted, irrespective of whether it was quoted or not on the original command line.

    Arguments with spaces wrapped in single quotes, will be re-quoted in double quotes?

    Yes.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    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.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    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.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 16, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    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.

  11. microsoft-github-policy-service
    added
    Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more
    on Nov 16, 2023
  12. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    microsoft-github-policy-serviceBot
    on Nov 23, 2023 – with Microsoft GitHub Policy Service
    Contributor
    More actions

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

    Reacted by Gerardo Grignoli and Bo Lingen
  13. microsoft-github-policy-service
    closed this as completedon Nov 23, 2023
  14. ForNeVeR commented on Mar 12, 2024

    @ForNeVeR
    Friedrich von Never (ForNeVeR)
    on Mar 12, 2024
    Contributor
    More actions

    Folks, this problem keeps reappearing from time to time in different random places (see the linked issues). Perhaps the bot was too eager to close it? I believe it should be addressed, for PowerShell to be a more robust / reliable tool for all the use cases.

    Currently, the argument/quotes parsing changes depending on the way you install PowerShell in your system. This can't be good, can it?

    Reacted by Gerardo Grignoli
  15. microsoft-github-policy-service
    added
    In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issue
    on Mar 12, 2024
  16. gerardog commented on Mar 13, 2024

    @gerardog
    Gerardo Grignoli (gerardog)
    on Mar 13, 2024
    More actions

    Thanks Friedrich von Never (@ForNeVeR)! After so much time...

    And yes, that bot is infuriating. I am very sorry to say this, but sometimes, negative feedback makes a difference, so here it goes: Steven Bucher (@StevenBucher98), when you activated the bot on Nov 16 2023 and gave just 6 days from warning to closure, you really messed up. This ticket is the proof of it. You should manually review all tickets closed on Nov 22, 2023 and evaluate if they need a second try.

    Reacted by Bo Lingen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Maintainers-Buildspecific to affecting the buildspecific to affecting the build

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.