mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-16 12:39:15 +08:00
18 lines
321 B
Go
18 lines
321 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 string(stderr.Bytes()), err
|
|
}
|
|
return string(stdout.Bytes()), nil
|
|
}
|