Skip to content

When calling cmd script, comma in string is not preserved  #11295

Closed
@jiasli

Description

@jiasli

Steps to reproduce

Create a batch file mybatch.cmd containing:

@echo off
echo %1
echo %2

In PowerShell call it with

PS C:\Users\me> .\mybatch.cmd "a,b"
a
b
PS C:\Users\me> .\mybatch.cmd 'a,b'
a
b
PS C:\Users\me> .\mybatch.cmd --% "a,b"
"a,b"
ECHO is off.  # this is expected in cmd
PS C:\Users\me> .\mybatch.cmd --% 'a,b'
'a
b'            # this is expected in cmd

Expected behavior

Comma inside the string should be preserved, like when calling it in cmd:

mybatch.cmd "a,b"
"a,b"
ECHO is off.

Actual behavior

Comma is parsed as array.

Environment data

$PSVersionTable 

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.6
PSEdition                      Core
GitCommitId                    7.0.0-preview.6
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

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 aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions