Std::process is escaping a raw string literal when I don't want it to

Sorry, I see, you are executing cmd.exe!

In that case, the problem is technically unsolvable, and that's a design flaw in Windows that has no solution due to backwards compatibility going all the way back to MS-DOS.

Commands executed in cmd.exe have no concept of quoting, no concept of escaping, because separation of arguments technically doesn't even exist. The command gets entire command as a single string (GetCommandLineW).

So what other systems that emulate concept of separate arguments do, is they hope command won't use GetCommandLineW literally, and instead will use CommandLineToArgvW, which defines its own (very quirky) syntax of separating arguments.

Your problem is that cmd.exe does not use CommandLineToArgvW, but parses its arguments itself, and the switch /c is magical and changes syntax of the rest of the line. Supporting this in a standard library like Rust's just doesn't make sense, since it would have to hardcode a specific exceptions for knowledge that this cmd.exe with this /c argument uses a custom parser, which is not compatible with CommandLineToArgvW.

2 Likes