CMake的execute_process和任意shell脚本 [英] CMake's execute_process and arbitrary shell scripts
问题描述
CMake的 execute_process
命令似乎只能让您执行一个过程-不能随意输入命令外壳。问题是,我想使用管道,文件描述符重定向等,但这似乎是不可能的。另一种选择对我来说会非常痛苦...
CMake's execute_process
command seems to only let you, well, execute a process - not an arbitrary line you could feed a command shell. The thing is, I want to use pipes, file descriptor redirection, etc. - and that does not seem to be possible. The alternative would be very painful for me (I think)...
我该怎么办?
PS-CMake 2.8和3.x答案很有趣。
PS - CMake 2.8 and 3.x answer(s) are interesting.
推荐答案
您可以使用shell的脚本执行任何shell脚本支持在字符串参数中使用脚本。
You can execute any shell script, using your shell's support for taking in a script within a string argument.
示例:
execute_process(
COMMAND bash "-c" "echo -n hello | sed 's/hello/world/;'"
OUTPUT_VARIABLE FOO
)
将导致 FOO
包含世界
。
当然,您需要小心转义引号和反斜杠。另外请记住,运行bash仅在具有 bash的平台上有效-即,它将无法在Windows上运行。
Of course, you would need to escape quotes and backslashes with care. Also remember that running bash would only work on platforms which have bash - i.e. it won't work on Windows.
这篇关于CMake的execute_process和任意shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!