1Panel/backend/utils/cmd/cmd.go
2022-11-18 18:05:02 +08:00

19 lines
307 B
Go

package cmd
import (
"bytes"
"os/exec"
)
func Exec(cmdStr string) (string, error) {
cmd := exec.Command("bash", "-c", cmdStr)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
return stderr.String(), err
}
return stdout.String(), nil
}