[CMake] EXECUTE_PROCESS and writing output to a file

Philippe Poilbarbe Philippe.Poilbarbe at cls.fr
Fri Jun 16 07:49:35 EDT 2006


Sylvain Benner a écrit :
> ...
> It works but it's not really what I want since it doesn't display the 
> output in real time.
> The process can be pretty long and the intermediate info are pretty 
> important.
> ...
On unix you can insert the 'tee' command
in the list of commands where you want
to keep the output stream.

Or as with my last answer do it in a more portable
way but using perl like this:

INCLUDE(FindPerl)

SET(THE_FILE "tee.txt")
EXECUTE_PROCESS(
        COMMAND ls
        COMMAND "${PERL_EXECUTABLE}" -e "open TEE, \">\", 
\"${THE_FILE}\" ; while(<STDIN>){print; print TEE;}"
        COMMAND tr [a-z] [A-Z]
        OUTPUT_VARIABLE OUTVAR)

MESSAGE("${OUTVAR}")

The 'tee' equivalent in perl is inserted between
'ls' and 'tr' and capture the original output from
ls before setting it uppercase
(ls and tr are here only to demonstrate the use
since it is not portable at all)

Philippe.



More information about the CMake mailing list