Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Difference in how PowerShell treats arguments vs CMD

Reply
 
Old 09-28-2006   #1 (permalink)
=?Utf-8?B?Q2hyaXN0aWFuIFRvcm5xdmlzdA==?=


 
 

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 SpecsSystem Spec
Old 09-28-2006   #2 (permalink)
Alex K. Angelopoulos [MVP]


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46