bashcmakestdoutio-redirectionstderr

How to save CMake output to file?


I can usually save the output of bash commands by >> output_file.txt

But when I execute cmake the output is still sent to the screen rather than output file as expected:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D \
BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D \
INSTALL_PYTHON_EXAMPLES=ON  -D BUILD_EXAMPLES=ON .. >> output_file.txt

Solution

  • That is because part (possibly all, depending on the situation) of your cmake output is streamed to stderr.

    Use this to redirect stderr to stdout:

    cmake ... >> output_file.txt 2>&1
    

    or append only stderr to output_file.txt:

    cmake ... 2>> output_file.txt