Reputation: 1411
I am trying to get information from file using regexp from withing a cmake file. Here is a simple file.txt located at my home directory:
entry1
entry2
In CMake I call grep in the following way:
SET(GREP_ARGS -oP \".*$\" /home/yuriy/file.txt)
MESSAGE(STATUS ${GREP_ARGS})
EXECUTE_PROCESS(
COMMAND
grep ${GREP_ARGS}
OUTPUT_VARIABLE MODULE_MSGS
ERROR_VARIABLE ERR)
However output/error variables are both empty. Moreover I am sure that the command is executed since if I change name of the file to non-existing one I got an error "No such file or directory" inside my output variable. Therefore it seems for me that the issue is in regular expression parameter passing. I have tried to wrap it with "
but it does not help.
Calling the same command from bash gives right output on Ubuntu 18.04:
grep -oP ".*$" /home/yuriy/file.txt
Thanks!
Upvotes: 1
Views: 1457
Reputation: 1411
Finally found a solution. The right way of setting arguments is without \"
symbols:
SET(GREP_ARGS -oP .*$ /home/yuriy/file.txt)
Not sure why is it so but it works.
Upvotes: 1