CMake不使用execute_process重定向stderr [英] CMake not redirecting stderr with execute_process

查看:180
本文介绍了CMake不使用execute_process重定向stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CMake将 stdout stderr 重定向到同一文件。我在CMake中使用 execute_process 选项和 ERROR_FILE OUTPUT_FILE 指定的选项。

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?

文件 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
)

文件 Tester.cmake

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


推荐答案

OUTPUT_FILE ERROR_FILE 指定相同的文件是最近才在CMake中添加的3.3。请参见发行说明

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

作为早期版本的解决方法,将选项 OUTPUT_VARIABLE ERROR_VARIABLE 与相同的变量,然后将变量的内容写入文件,例如:

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}")

这篇关于CMake不使用execute_process重定向stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆