[CMake] Can't run cmd.exe directly in ctest?

Dan Kegel dank at kegel.com
Mon Aug 25 13:59:10 EDT 2014


Hi!  The simple CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(foo)
enable_testing()
add_test(NAME bar COMMAND cmd /c echo hello)

fails for me when run on Windows 7 64 bit (only platform I've tried)
with ctest 2.8.12 or 2.8.11.
"ctest -V -C Debug" outputs

...
test 1
    Start 1: bar

1: Test command: C:\Windows\System32\cmd.exe "/c" "echo" "hello"
1: Test timeout computed to be: 9.99988e+006
1: The syntax of the command is incorrect.
1/1 Test #1: bar ..............................***Failed    0.07 sec

Watching with ProcessMonitor, the only funky business I can see is
that ctest uses forward slashes in the path it passes to
CreateProcess.

Trying this with a little C program shows that, yes, cmd.exe outputs
"The syntax of the command is incorrect" if run with
    CreateProcess( NULL, "c:/windows/system32/cmd.exe /c echo hi", ...)
but executes properly if run with
    CreateProcess( NULL, "c:\\windows\\system32\\cmd.exe /c echo hi", ...)

The obvious workaround is... just use a bat file without mentioning cmd at all:

cmake_minimum_required(VERSION 2.8)
project(foo)
enable_testing()
add_test(NAME bar COMMAND foobar.bat)

If you forget to do chmod +x foobar.bat first, it'll fail with "***Not Run".

The only reason I'm posting this is because I forgot to do the chmod
+x, and tried using
cmd directly without a batch file as a minimal test case.  Bit of a detour :-)
- Dan


More information about the CMake mailing list