fix(docker-exec-via-sock): 调整日志输出和命令执行结果的输出方式
This commit is contained in:
@@ -5,7 +5,7 @@ set -eu
|
||||
# 示例: ./docker-exec-via-sock.sh --container=my-container --cmd="ls -l /"
|
||||
|
||||
log() {
|
||||
printf '%s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ') $*"
|
||||
printf '%s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ') $*" >&2
|
||||
}
|
||||
|
||||
log_stream() {
|
||||
@@ -194,11 +194,13 @@ exit_code=$(docker_exec_exit_code "$exec_id")
|
||||
|
||||
if [ "$exit_code" = "0" ]; then
|
||||
log "command finished successfully"
|
||||
log_stream "output" "$output"
|
||||
# 将纯净的输出打印到 stdout
|
||||
printf '%s' "$output"
|
||||
exit 0
|
||||
else
|
||||
log "command failed with exit code $exit_code"
|
||||
log "output from container:"
|
||||
printf '%s\n' "$output"
|
||||
# 将错误输出打印到 stderr
|
||||
printf '%s\n' "$output" >&2
|
||||
exit "$exit_code"
|
||||
fi
|
||||
Reference in New Issue
Block a user