Question Environment.GetCommandLineArgs() splits string with spaces in it sometimes not others

shell_l_d

New member
Joined
Sep 21, 2010
Messages
4
Programming Experience
Beginner
Environment.GetCommandLineArgs() splits string with spaces in it sometimes but not others, want to avoid this.


EXAMPLE 1: command Line Arg (WRONG)
@rpt=D:Test.rpt,@dsn=Test.dsn,@export=pdf,@destination=D:\AutoRpt\Test.pdf,@@startd=-1,@@endd=0,@@whichclient=Joe Bloggs,@Email=no,@EmailParam=1

Gives this
1 = "@rpt=D:Test.rpt,@dsn=Test.dsn,@export=pdf,@destination=D:\AutoRpt\Test.pdf,@@startd=-1,@@endd=0,@@whichclient=Joe"
2 = "Bloggs,@Email=no,@EmailParam=1"

But want it to give this:
1 = "@rpt=D:Test.rpt,@dsn=Test.dsn,@export=pdf,@destination=D:\AutoRpt\Test.pdf,@@startd=-1,@@endd=0,@@whichclient=Joe Bloggs,@Email=no,@EmailParam=1"


EXAMPLE 2: command Line Arg (WORKS)
"@rpt=D:Test.rpt,@dsn=Test.dsn,@export=pdf,@destination=D:\AutoRpt\Test.pdf,@@startd=-1,@@endd=0,@@whichclient=Joe Bloggs,@Email=no,@EmailParam=1"

Gives this
1 = "@rpt=D:Test.rpt,@dsn=Test.dsn,@export=pdf,@destination=D:\AutoRpt\Test.pdf,@@startd=-1,@@endd=0,@@whichclient=Joe Bloggs,@Email=no,@EmailParam=1"


EXAMPLE 3: command Line Arg (WORKS)
"this is a test" string to see "what happens"

Gives this:
1 = this is a test
2 = string
3 = to
4 = see
5 = what happens


Workaround for EXAMPLE 1: join array elements when next array element's first char isn't a "@"

Is there a delimiter that can be used to avoid this?

I've tried these in the above command line, to no avail:
'Joe Bloggs'
"Joe Bloggs"
""Joe Bloggs""
[Joe Bloggs]
Joe\ Bloggs
\"Joe Bloggs\"


P.S. This was a VB6 command line app that I just converted to VB.net & the behaviour only occurs in the VB.net version. It's being called in many places at the moment, so don't really want to have to manually go through all calls & add double quotes around the whole argument.
 

shell_l_d

New member
Joined
Sep 21, 2010
Messages
4
Programming Experience
Beginner
I realised this shortly after posting that Example 2 is how my application should be being called & went searching for all the command line calls to the exe & added the double quotes around the entire 1 command line argument (as in Example 2) & it's been working well since.

The VB6 app code was using something similar to Environment.GetCommandLineArgs() which obviously works differently.
 
Top Bottom