Skip to content

7.2.0-preview9: & arguments no longer remove quotes #16017

Closed

Description

@nohwnd

Prerequisites

Steps to reproduce

Have a program that just prints out it's args:

using System;
using System.Linq;

namespace ConsoleApp29
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Arguments:");
            args.ToList().ForEach(arg => Console.WriteLine(arg));
        }
    }
}

Invoke the program with & and pass some params.

Expected behavior

& ".\ConsoleApp29.exe" @("a", '"a"')

Arguments:
a
a

Actual behavior

& ".\ConsoleApp29.exe" @("a", '"a"')

Arguments:
a
"a"

Error details

The "" are no longer stripped from the argument in 7.2.0-preview9, while in 7.1.3 they are stripped.

Environment data

$psversiontable

Name                           Value
----                           -----
PSVersion                      7.2.0-preview.9
PSEdition                      Core
GitCommitId                    7.2.0-preview.9
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

Visuals

No response

Activity

  1. SeeminglyScience commented on Aug 30, 2021

    @SeeminglyScience
    Contributor

    This is due to the experimental feature PSNativeCommandArgumentParsing. As a workaround, you can disable the feature or control it with this variable:

    $oldMode = $PSNativeCommandArgumentPassing
    try {
        $PSNativeCommandArgumentPassing = 'Legacy'
        InvokeExeHere
    } finally {
        $PSNativeCommandArgumentPassing = $oldMode 
    }
  2. nohwnd commented on Aug 30, 2021

    @nohwnd
    CollaboratorAuthor

    Thanks Patrick.

    Medeni Baykal (@Haplois) This should also work, when relying on scoping to reset it for us:

    & { 
        $PSNativeCommandArgumentPassing = 'Legacy'
        InvokeExeHere
    }
  3. jborean93 commented on Aug 30, 2021

    @jborean93
    Collaborator

    Just as an FYI this should be the desired behaviour as it is escaping the values correctly. It will allow you to do my.exe '{"foo": "bar"}' without you having to manually escape the double quotes yourself. The only exceptions would be executables that don't follow the standard MS C argument escaping convention which there are some out there.

  4. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Aug 31, 2021
  5. ghost closed this as completedon Sep 1, 2021
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

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-AnsweredThe question is answered.WG-Engine-ParameterBinder

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions