This question already has an answer here:<ul><li> <a href="/questions/35689501/cmakes-execute-process-and-arbitrary-shell-scripts" dir="ltr" rel="nofollow">CMake's execute_process and arbitrary shell scripts</a> <span class="question-originals-answer-count"> 2 answers </span> </li> </ul>
I wanted to extract a string from a header in an
But there is a bug with the command and I try a lot of things, always the same error.
COMMAND cat $(version_h) | grep -a "define myVersion " | cut -d " " -f3 | cut -d '"' -f2`
If I write the command in the console line, there is no problem.
The error says: "Parse error. Function missing ending ")". Instead found unterminated string with text " "Answer1:
execute_process() only deals with processes and their arguments, i.e. there is no shell involved.
So, you have two main options:<ol><li>
execute_process(COMMAND bash -c "..." OUTPUT_VARIABLE _Version)</li> <li>
execute_process(COMMAND cat ... COMMAND grep ... COMMAND cut ... COMMAND cut ... OUTPUT_VARIABLE _Version)</li> </ol>
In the second version, the standard output and standard inputs of the commands chain together.
If you want to do anything more complex, you'll have to create a separate script and invoke it in a process-, not shell-, oriented way, i.e. option 1.Answer2:
The problem was that I need to remove a quote character and I guess there is a confusion with Cmake and the bash command.
execute_process(COMMAND cat ... COMMAND grep ... COMMAND cut ... COMMAND cut -c2- COMMAND rev COMMAND cut -c2- COMMAND rev OUTPUT_VARIABLE _Version)