![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Difference in how PowerShell treats arguments vs CMD Hi, In CMD, the following commandline: program.exe foo.bar foo -foo.bar results in 3 arguments (as expected). The same commandline in PowerShell results in 4 arguments: 1: foo.bar 2: foo 3: -foo 4: .bar Is it supposed to be this way? I've found a workaround by quoting my arguments that starts with a '-' and contains a dot, but it's very annoying that it differs between cmd and powershell... Best regards, Christian |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Difference in how PowerShell treats arguments vs CMD Works the same way with colons, too. :| It's a bit difficult to do because PowerShell actually handles _all_ of the parsing, _then_ does the command name matching and passes the parsed arguments as an argument vector. I think the "." recognition might be a bug since it forces a break but is not consumed in normal PS use; for example, the command Write-Host -Object.Hello will display .Hello There is also another simpler workaround you can use. If you precede the - with the ` escape character, PowerShell will not interpret it as a parameter name. This allows you to reserve your quotes for when you really need them. For example: PS> Write-Host `-Object:Hello -Object:Hello "Christian Tornqvist" <Christian Tornqvist@discussions.microsoft.com> wrote in message news:77612C07-EFE3-4557-AC64-0C61103FEC40@microsoft.com... > Hi, > > In CMD, the following commandline: > > program.exe foo.bar foo -foo.bar > > results in 3 arguments (as expected). The same commandline in PowerShell > results in 4 arguments: > > 1: foo.bar > 2: foo > 3: -foo > 4: .bar > > Is it supposed to be this way? I've found a workaround by quoting my > arguments that starts with a '-' and contains a dot, but it's very > annoying > that it differs between cmd and powershell... > > Best regards, > Christian |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Gnu argp or getopt like arguments processor for Powershell? | PowerShell | |||
| how to execute a batch file with arguments from powershell | PowerShell | |||
| Passing arguments from .BAT to PowerShell script | PowerShell | |||
| Re: how to see arguments with powershell when running winrs | PowerShell | |||
| powershell arguments : PARAM vs ARGS ? | PowerShell | |||