Environment.GetCommandLineArgs bug ???

  • Thread starter Thread starter BBVan
  • Start date Start date
B

BBVan

I'm passing quoted path parameters to a VB .NET program and using the following declarations to retrieve them:
Dim szCommandLine As String = Environment.CommandLine
Dim szArgs() As String = Environment.GetCommandLineArgs()
When I look at the entire command line , the arguments are quoted. i.e.
szCommandLine equals "C:\test\FileSearch.exe" "E:\"

When I use GetCommandLineArgs to split the arguments into a string array, the quotes are removed and the trailing back slash removed and I getting the following results:
szArgs(0) equals C:\test\FileSearch.exe
szArgs(1) equals E:"

I'm running Windows XP Professional and using Visual Studio .NET 2003.

The documentation states that GetCommandLineArgs returns
An array of string where each element contains a command line argument. The first element is the executable file name, and the following zero or more elements contain the remaining command line arguments.

I've gotten around this by parsing the entire command line myself but I'd like to know if this is a problem or am I misunderstanding the documentation?

Thanks

Brant
 
I tried this in C#, VB .NET, and a native C++ app and the behavior is the same for all. It seems like this is a bug at the Windows level. If so, then it's unlikely to get fixed due to the fact it would probably break thousands of apps.

I'm passing quoted path parameters to a VB .NET program and using the following declarations to retrieve them:
Dim szCommandLine As String = Environment.CommandLine
Dim szArgs() As String = Environment.GetCommandLineArgs()
When I look at the entire command line , the arguments are quoted. i.e.
szCommandLine equals "C:\test\FileSearch.exe" "E:\"

When I use GetCommandLineArgs to split the arguments into a string array, the quotes are removed and the trailing back slash removed and I getting the following results:
szArgs(0) equals C:\test\FileSearch.exe
szArgs(1) equals E:"

I'm running Windows XP Professional and using Visual Studio .NET 2003.

The documentation states that GetCommandLineArgs returns
An array of string where each element contains a command line argument. The first element is the executable file name, and the following zero or more elements contain the remaining command line arguments.

I've gotten around this by parsing the entire command line myself but I'd like to know if this is a problem or am I misunderstanding the documentation?

Thanks

Brant
 
The \" part of the argument "E:\" is taken as an escape sequence. The
double quotes is 'escaped' by using the slash, which is why the
back-slash does not appear in the parsed argument, but double quotes
does.

One way to get around this is escape the back-slash itself:

"E:\\"

Karun.
 
When the shell passes the exe path to the app, it escapes all of the
backslahes automatically, however it does not do that for arguments.
 
Back
Top