3 ms·
> And unfortunately, the cmd.exe has different escaping rules compared to the usual escaping mechanism. This "usual escaping mechanism" is a bit of a weasel wo
by kazinator 3y ago
> And unfortunately, the cmd.exe has different escaping rules compared to the usual escaping mechanism.
This "usual escaping mechanism" is a bit of a weasel word. Windows passes a single null-terminated character string to a process. Every application run-time must parse that into arguments itself.
I think what "usual escaping mechanism" refers to is the algorithm implemented in the Microsoft Visual C Run Time which takes the command line string and produces a char *argv[] for the main function.
There is no telling what uses that exact algorithm and what doesn't. Programs built with Microsoft languages probably do; obviously VC and VC++.
- MarkSweep 3y agoThe “usual escaping mechanism” may also refer to CommandLineToArgvW, a Windows API function that implements this. I think it is a pretty common way to implement the parsing side, though I’m not sure if the Visual C runtime does something different. https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw https://learn.microsoft.com/en-us/windows/win32/api/shellapi...
- MarkSweep 3y agoSome more details on this, apparent CommandLineToArgvW implements a slightly different parsing algorithm that the Visual C++ runtime: https://learn.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?view=msvc-170#parsing-c-command-line-arguments https://learn.microsoft.com/en-us/cpp/cpp/main-function-comm... Also, here is another implementation of this algorithm in C#, used in .NET: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs#L223 https://github.com/dotnet/runtime/blob/main/src/libraries/Sy...