From 6c27561447c426c89b46ccda70213319fb17ad23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Tue, 23 Sep 2025 11:20:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(docker-exec-via-sock):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E5=92=8C=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=BB=93=E6=9E=9C=E7=9A=84=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-exec-via-sock.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docker-exec-via-sock.sh b/docker-exec-via-sock.sh index dc3c20d..e6d0062 100644 --- a/docker-exec-via-sock.sh +++ b/docker-exec-via-sock.sh @@ -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 \ No newline at end of file