部署到本地、执行命令公共方法、ssh部署port字段修改为泛型

This commit is contained in:
zhangchenhao
2025-05-14 10:57:50 +08:00
parent 640e62f757
commit de05da9cf1
3 changed files with 88 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package public
import (
"bytes"
"crypto/rand"
"fmt"
"github.com/google/uuid"
@@ -8,6 +9,8 @@ import (
"math/big"
"net"
"net/http"
"os/exec"
"runtime"
"strings"
)
@@ -200,3 +203,23 @@ func ContainsAllIgnoreBRepeats(a, b []string) bool {
}
return true
}
// ExecCommand 执行系统命令,并返回 stdout、stderr 和错误
func ExecCommand(command string) (string, string, error) {
var cmd *exec.Cmd
// 根据操作系统选择解释器
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/C", command)
} else {
cmd = exec.Command("bash", "-c", command)
}
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}