Can't execute Windows batch built-in commands with forward slashes on paths
Operating system: Windows 10 64bit, Version 1709 (Build 16299.19) CMake: 3.9.4
Batch built-in commands are not supported in CMake execute_process
directive. This is unfortunate since there are some useful commands like mklink
that are not available as executables. The trick to make them callable in cmake is to prefix them with batch calling cmd /C command
. Also batch evaluation seems to prevent evaluating paths with forward slashes, unless they are quoted. So for example:
>cmd /c dir C:/
Invalid switch - "".
The command will work correctly only with the path quoted:
>cmd /c dir "C:/"
Volume in drive C has no label.
Volume Serial Number is A2C9-35E5
Directory of C:\
[..]
Now, if I try to execute the same command with CMake putting it in a script.cmake
:
set(builtin "dir \"C:/\"")
message("cmd /c ${builtin}")
execute_process(COMMAND cmd /c "${builtin}")
I get:
>cmake -P script.cmake
cmd /c dir "C:/"
The filename, directory name, or volume label syntax is incorrect.
If I remove the escaped quotes I get the same error as regular batch evaluation:
>cmake -P script.cmake
cmd /c dir C:/
Invalid switch - "".
Other tries still won't allow me to call the builtin command in CMake with paths with forward slashes.