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
包含 world
.
当然,您需要小心转义引号和反斜杠.还要记住,运行 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屋!