View Single Post
Old 05-11-2007   #1 (permalink)
Dan


 
 

Argument that starts with '-' and contains ':' gets separated.

I discovered that when I execute a program from the PS command line
and I try to pass an argument that starts with a hyphen (-) and
contains a colon (, the argument will be split into 2 arguments at
the colon.

To demonstrate, I wrote a simple python script then merely echoes out
all the arguments in argv:

PS C:\3rdParty> .\testPSArgs.py c:\goodbye
arg: C:\3rdParty\testPSArgs.py
arg: c:\goodbye
PS C:\3rdParty> .\testPSArgs.py =c:\goodbye
arg: C:\3rdParty\testPSArgs.py
arg: =c:\goodbye
PS C:\3rdParty> .\testPSArgs.py hello=c:\goodbye
arg: C:\3rdParty\testPSArgs.py
arg: hello=c:\goodbye
PS C:\3rdParty> .\testPSArgs.py -hello=c:\goodbye
arg: C:\3rdParty\testPSArgs.py
arg: -hello=c:
arg: \goodbye

Now, of course, the workaround is fairly simple, merely enclose the
argument in quotes:
PS C:\3rdParty> .\testPSArgs.py "-hello=c:\goodbye"
arg: C:\3rdParty\testPSArgs.py
arg: -hello=c:\goodbye

I was just wondering, why does it parse the command line in this way?

thanks,
Dan

My System SpecsSystem Spec