Tuesday, June 23, 2009

Issue with parsing command lines containing path in c#

Hi!
Another strange detail of .NET/C#:
I needed to pass two pathes to c# command line arguments, and wasn't able to control whether they are ended with backslash or not. Really it was a C# post-build tool so arguments were passed by MsBuild. Final command line looked like following:
"C:\My Path\My Program.exe" "C:\First Path\" "C:\Second Path\"
However C# command-line parser treats \" as esacape sequence
so for this sample
args[0]=="C:\\First Path\" "
and args[1]=="C:\Second"
and even args[2]=="Path\"".
Absolutely unacceptable, isn't it?
The only way to solve it I can see is to get the whole original command line from Environment.CommandLine and have your own parser. Please remember that this value includes executable name as well that may be or may be not quoted too.

Some explanation is here:
http://www.eggheadcafe.com/conversation.aspx?messageid=31268633&threadid=31268617

No comments:

Post a Comment