CMake not redirecting stderr with execute_process

荒凉一梦 提交于 2019-12-08 06:41:03

问题


I'm trying to redirect stdout and stderr to the same file using CMake. I'm using the execute_process option in CMake with the ERROR_FILE and OUTPUT_FILE option specified.

I'm successfully capturing the output, but the error is not there. What am I doing wrong?

File CMakeLists.txt

add_test(NAME test${ID}
    COMMAND ${CMAKE_COMMAND}
    -DEXE=../examples/test${exampleID}
    -DID=${ID}
    -DARGS=${args}
    -P ${CMAKE_CURRENT_SOURCE_DIR}/Tester.cmake
)

File Tester.cmake

separate_arguments( ARGS )
# Run the test
execute_process( 
    COMMAND "${EXE}" ${ARGS}
    ERROR_FILE test${ID}.out
    OUTPUT_FILE test${ID}.out
)

回答1:


Specifying the same file for both OUTPUT_FILE and ERROR_FILE has only recently been added in CMake 3.3. See release notes.

As a work-around for earlier versions, use the options OUTPUT_VARIABLE and ERROR_VARIABLE with the same variable and then write the contents of the variable to the file, e.g.:

execute_process( 
    COMMAND "${EXE}" ${ARGS}
    ERROR_VARIABLE _testOut
    OUTPUT_VARIABLE _testOut
)
file (WRITE "test${ID}.out" "${_testOut}")


来源:https://stackoverflow.com/questions/31523014/cmake-not-redirecting-stderr-with-execute-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!