I’m trying to execute a batch script with an argument that requires double quotes, something like script.bat "foo=bar". If this argument is passed in without the double quotes, you end up with %1 being “foo” and %2 being “bar”, instead of the desired %1 being “foo=bar”.
With single double quotes around the argument (execute_process(COMMAND script.bat "foo=bar")) I get no quotes in the call. All other combinations of escaping seem to propagate the escape to the call itself, with backslashes in the arg.
Is this possible without writing an intermediary batch script to call this other batch script?
Your example just has a CMake string defined, without any quotes.
CMake just allows you to omit the " around string, as long as you don’t have whitespaces or semicolons as content.
Have you tried this: execute_process(COMMAND script.bat "\"foo=bar\"")
Or if there is no variable involved: execute_process(COMMAND script.bat [["foo=bar"]])
Craig Scott wrote a blog article, that might help you in understanding quoting:
execute_process assumes that the child uses the MSVC C runtime library’s CommandLineToArgvW to parse the command line. In order to do anything different, a new option will be needed.
CMake Issue 16321 requests a way to control the raw command line on Windows.