-
Notifications
You must be signed in to change notification settings - Fork 290
Trailing back-slash in String argument value leads to incorrect parsing #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's the magic of .Net.
The quick fix: put a double-slash at the end of your path instead of a single one. Since .Net does some pre-processing of arguments to get your That has some trade-offs since |
It could be worth considering parsing System.Environment.CommandLine then, which preserves the correct arguments. |
I feel like some documentation regarding this would be beneficial... basically that the recommended approach is to utilize the System.Environment.CommandLine instead of string[] args from Main. |
@ericnewton76 This would probably take the form of a new overload for |
It goes down to the Windows API, CommandLineToArgvW. There's a lot of material about this weird behavior, like https://blogs.msdn.microsoft.com/oldnewthing/20100917-00/?p=12833/ Funny thing, it seems that DOS bat files behave differently. Wondering if they use a different API or if cmd reimplemented command line parsing. sample.cmd "this works\fine" "hello" |
Yep, one argument against it is that the current behavior is standard, if quirky. Those familiar with Windows command line who know about escaping slashes may expect your tool to behave the same way. |
Right, that's a valid point. I tried other command line libraries and they all rely on the same behavior. Probably we can live with it :) |
Hi,
as subject.
Given a -p String parameter:
ReadText.Demo.exe head -p "c:\trailing - back - slash"
It gets parsed as:
c:\trailing - back - slash"
The trailing back-slash causes the value of the parameter to hold the double-quote value, while the back-slash is lost.
This seems to happen only when the traling back-slash is immediately followed by the double-quote.
Thanks
The text was updated successfully, but these errors were encountered: