gpt4 book ai didi

bash - 如何在 bash 中捕获 gitlab-runner 的输出

转载 作者:行者123 更新时间:2023-12-03 01:39:49 25 4
gpt4 key购买 nike

为什么当我写入终端时

#!/bin/bash
out=`gitlab-runner list`
echo "list: ${out}"

out 变量仍然为空并且命令的输出始终显示在终端中? Install Gitlab Runner

我如何捕获这个输出?

最佳答案

gitlab-runner list 在 stderr 上输出列表,因此您不会将其捕获为 stdout 的输出。

参见Bash how do you capture stderr to a variable?

并将脚本更改为:

#!/bin/bash
out="$(gitlab-runner list 2>&1)"
echo "list: ${out}"

关于bash - 如何在 bash 中捕获 gitlab-runner 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52324897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com