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

feat: 优化对 OpenResty 端口的处理

This commit is contained in:
耗子
2023-11-19 02:10:39 +08:00
parent ff60fb44b7
commit fc9ca25a46
6 changed files with 33 additions and 31 deletions

View File

@@ -1,6 +1,8 @@
package tools
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
@@ -39,8 +41,16 @@ func Remove(path string) error {
func Exec(shell string) (string, error) {
cmd := exec.Command("bash", "-c", "LC_ALL=C "+shell)
output, err := cmd.CombinedOutput()
return strings.TrimSpace(string(output)), err
var stdoutBuf, stderrBuf bytes.Buffer
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
err := cmd.Run()
if err != nil {
return "", errors.New(strings.TrimSpace(stderrBuf.String()))
}
return strings.TrimSpace(stdoutBuf.String()), err
}
// ExecAsync 异步执行 shell 命令