From cdc0ac72ae0145d0f6bfe50a9fcd5e9a47aef359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 10 Jan 2026 00:32:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=83=B5=E5=B0=B8=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/shell/exec.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/shell/exec.go b/pkg/shell/exec.go index 4116561c..ba610afd 100644 --- a/pkg/shell/exec.go +++ b/pkg/shell/exec.go @@ -138,7 +138,7 @@ func ExecfWithOutput(shell string, args ...any) error { } // ExecfWithPipe 执行 shell 命令并返回管道 -func ExecfWithPipe(ctx context.Context, shell string, args ...any) (out io.ReadCloser, err error) { +func ExecfWithPipe(ctx context.Context, shell string, args ...any) (io.ReadCloser, error) { if !preCheckArg(args) { return nil, errors.New("command contains illegal characters") } @@ -149,14 +149,17 @@ func ExecfWithPipe(ctx context.Context, shell string, args ...any) (out io.ReadC _ = os.Setenv("LC_ALL", "C") cmd := exec.CommandContext(ctx, "bash", "-c", shell) - out, err = cmd.StdoutPipe() + out, err := cmd.StdoutPipe() if err != nil { - return + return nil, err } cmd.Stderr = cmd.Stdout err = cmd.Start() - return + + go func() { _ = cmd.Wait() }() + + return out, err } // ExecfWithDir 在指定目录下执行 shell 命令