I have a .net / c# command line application that takes a couple par开发者_运维问答ameters in the format like:
some.exe -p1:value -p2:someothervalue
etc
A complete sample call looks like this:
JobWorker.exe -j:b38815af-68ce-4cb9-a858-3c016cc3c033 -cs:fors37ca -ch:384 -s:fors37ea -dp:667 -op:B:\ -ci:"d:\TFS\iRMA-4.2-P1\Applications.JobExecutor\bin\x86\Debug\Image Cache\" -cas:fors35fa -cap:333 -gs:fors395a -gb:gibraltar -gt:5 -jn:"DocumentJob #iRMA FSP #Some User Name #Open #6/16/2011"
Now for some reason the -ci:"d:...." part breaks the string[] args up weirdly, see with the -ci: one:
vs without:
Everything past the -ci: part gets messed up.. for some reason & I am wondering what it is? Any ideas?
Per msdn
A double quotation mark preceded by a backslash (\") is interpreted as a literal double quotation mark character (")
http://msdn.microsoft.com/en-us/library/78f4aasd(v=vs.80).aspx
It sees it as a literal and doesn't close the argument.
I think liho1eye has it right in the comment.
This really has nothing to do with .NET and more to do with what method you're using to pass the args to your program.
Are you running it from a CMD.exe shell?
The fix is to either get rid of the trailing backslash, or double it, like so:
-ci:"d:\TFS\iRMA-4.2-P1\Applications.JobExecutor\bin\x86\Debug\Image Cache\\"
You have a very complex command line that takes a lot of arguments and it is probably generated programmatically (I hope so anyway.) Since it is complex and you're needing to allow troublesome characters then I would suggest passing a single, base64-encoded block as an argument that contains all of the parameter information. It's a sort of poor-man's serializer but, it protects your command from a lot of weirdness that comes from passing args via command line and the dozen or so special characters such as pipes and angle braces: | < > and several others. You can decode and parse out the base64 block inside your logic without worrying about special characters.
So with base64 encoding your command would look like:
JobWorker.exe LWo6YjM4ODE1YWYtNjhjZS00Y2I5LWE4NTgtM2MwMTZjYzNjMDMzIC1jczpmb3JzMzdjYSAtY2g6Mzg0IA0KLXM6Zm9yczM3ZWEgLWRwOjY2NyAtb3A6QjpcIA0KLWNpOiJkOlxURlNcaVJNQS00LjItUDFcQXBwbGljYXRpb25zLkpvYkV4ZWN1dG9yXGJpblx4ODZcRGVidWdcSW1hZ2UgQ2FjaGVcIiANCi1jYXM6Zm9yczM1ZmEgLWNhcDozMzMgLWdzOmZvcnMzOTVhIC1nYjpnaWJyYWx0YXIgLWd0OjUgDQotam46IkRvY3VtZW50Sm9iICNpUk1BIEZTUCAjU29tZSBVc2VyIE5hbWUgI09wZW4gIzYvMTYvMjAxMSI=
You can verify the en/decoding here, and many other online locations.
精彩评论