[CMake] Problem piping 'execute_process' output
J.S. van Bethlehem
j.s.van.bethlehem at astro.rug.nl
Fri Apr 29 05:46:29 EDT 2011
Hello,
Since I'm only just starting to learn how to use CMake I'm not sure
whether I found a bug, or whether I'm misunderstanding something. So I
figured I could just as well see what others have to say about it.
I managed to create a minimalistic example using CMake 2.8.4:
Suppose I have the following simple code (say source.cc):
#include <iostream>
using namespace std;
int main() {
cout << "Some info to std::cout\n";
cerr << "Some info to std::cerr\n";
return 0;
}
Somewhere along the line of building my project I want to run this
source and pipe the output to 'source.out'. For this example I'll
manually build the executable source.cc -> source.out and write the
names of all files explicitly in the following one-line CMake-file (say
RunCommand.cmake):
# - run 'source' and pipe output to source.out
execute_process(COMMAND ./source OUTPUT_FILE source.out ERROR_FILE
source.out)
In reality I'd call this script through '${CMAKE_COMMAND} -P
${CMAKE_MODULE_PATH}/RunCommand.cmake' from some CMakeLists.txt file
with variables storing the binary and output through a set of -D
options. But now I do:
cmake -P RunCommand.cmake
I would expect to see both lines in 'source.out'. But in reality only
the second line, that went to the error stream is in the outputfile.
Interestingly, if I change the ordering of the two lines in source.cc,
again only the second line appears (now the 'cout' line) Only if I send
both lines to the same stream, either cout or cerr, I get both lines in
the outputfile.
Am I trying do something that is not possible (I think not, given that
the manual explicitly states that OUTPUT_* and ERROR_* may be the same
and that results will be merged), do I need to add some more syntax, or
did I stumble across a genuine bug?
Yours sincerely,
Jakob van Bethlehem
More information about the CMake
mailing list