2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 09:13:49 +08:00

refactor: 面板websocket

This commit is contained in:
耗子
2024-10-20 22:14:11 +08:00
parent 892f91be3e
commit ff239c467a
14 changed files with 320 additions and 214 deletions

View File

@@ -2,8 +2,10 @@ package shell
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"strings"
@@ -90,3 +92,19 @@ func ExecfWithOutput(shell string, args ...any) error {
return cmd.Run()
}
// ExecfWithPipe 执行 shell 命令并返回管道
func ExecfWithPipe(ctx context.Context, shell string, args ...any) (out io.ReadCloser, err error) {
_ = os.Setenv("LC_ALL", "C")
cmd := exec.CommandContext(ctx, "bash", "-c", fmt.Sprintf(shell, args...))
out, err = cmd.StdoutPipe()
if err != nil {
return
}
cmd.Stderr = cmd.Stdout
err = cmd.Start()
return
}