MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Creative Commons Attribution 4.0 International
1.93k stars 1.55k forks source link

about_Pwsh.md is missing no-loc terms for CommandWithArgs and clarify cmd.exe error #11234

Closed ninmonkey closed 1 week ago

ninmonkey commented 1 week ago

Prerequisites

Links

Summary

1] The no-loc metadata is missing the Command -CommandWithArgs and its alias -cwa

2] The example given works, but only when it's launched from a pwsh.exe but not cmd.exe or powershell.exe

I thought the cmd.exe and powershell.exe cases were common enough to be worth mentioning.

Details

For completion here's fixes for all 4 cases:

# When ran from cmd.exe
# ( the original throws )
pwsh -CommandWithArgs "$args | % { ""arg: $_"" }" arg1 arg2

# from a pwsh session with default values
# ( the original works )
pwsh -CommandWithArgs '$args | % { "arg: $_" }' arg1 arg2

# ran from a  powershell.exe session 5.1
# ( the original outputs blank ) 
pwsh -CommandWithArgs '"$args | % { ""arg: $_"" }"' arg1 arg2

# from a pwsh session using legacy argument passing
# ( the original outputs blank )
$PSNativeCommandArgumentPassing = 'Legacy'
pwsh -CommandWithArgs '$args | % { ""arg: $_"" }' arg1 arg2

Tested using pwsh 7.4.2 and powershell 5.1

Suggested Fix

Maybe Part 2 should simplify to the info link about_parsing#passing-arguments-that-contain-quote-characters

I included examples because common cases fail. Some show no errors. That could be confusing for users


Part 3 I am not sure if this is correct behavior or possibly a bug? The lack of syntax error is what originally triggered these tests.

# start a new pwsh -nop session, then 
$PSNativeCommandArgumentPassing = 'legacy'
pwsh -nop -CommandWithArgs '$args | % { "arg: $_" }' arg1 arg2
# no errors, no output. 
sdwheeler commented 1 week ago

Part 3 I am not sure if this is correct behavior or possibly a bug? The lack of syntax error is what originally triggered these tests.

Please file an issue with the PowerShell team.