使用 bash 管道的 CMake executing_process
CMake executing_process with bash pipeline
在我的 CMakeLists.txt
中,我需要执行位于 /include/ff 下的 mapping_string.sh 脚本。此脚本需要用户键入“y”才能继续。
我试过这种方法,但我只得到一个无限打印的“mapping_string.sh”字符串。
execute_process(
COMMAND yes | bash mapping_string.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/ff
RESULT_VARIABLE FF_MS_RES
)
with bash pipeline
即管道是 Bash 的一部分,你必须 运行 Bash,而不是其他东西。
execute_process(
COMMAND bash -c "yes | bash mapping_string.sh"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/ff
RESULT_VARIABLE FF_MS_RES
)
请务必阅读有关在 CMake 中引用的内容 https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#quoted-argument。
使用 execute_process
命令的内置功能代替管道:
Commands are executed concurrently as a pipeline, with the standard output of each process piped to the standard input of the next. A single standard error pipe is used for all processes.
execute_process(
COMMAND yes
COMMAND bash mapping_string.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/ff
RESULT_VARIABLE FF_MS_RES
)
在我的 CMakeLists.txt
中,我需要执行位于 /include/ff 下的 mapping_string.sh 脚本。此脚本需要用户键入“y”才能继续。
我试过这种方法,但我只得到一个无限打印的“mapping_string.sh”字符串。
execute_process(
COMMAND yes | bash mapping_string.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/ff
RESULT_VARIABLE FF_MS_RES
)
with bash pipeline
即管道是 Bash 的一部分,你必须 运行 Bash,而不是其他东西。
execute_process(
COMMAND bash -c "yes | bash mapping_string.sh"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/ff
RESULT_VARIABLE FF_MS_RES
)
请务必阅读有关在 CMake 中引用的内容 https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#quoted-argument。
使用 execute_process
命令的内置功能代替管道:
Commands are executed concurrently as a pipeline, with the standard output of each process piped to the standard input of the next. A single standard error pipe is used for all processes.
execute_process(
COMMAND yes
COMMAND bash mapping_string.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/ff
RESULT_VARIABLE FF_MS_RES
)