Environment.GetCommandLineArgs bug ???

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
 
E

Ed Kaim [MSFT]

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
 
K

Karun

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.
 
E

Ed Kaim [MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top