2022-10-09 23:35:24 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-11-08 15:42:31 +08:00
|
|
|
"bytes"
|
2022-10-09 23:35:24 +08:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2022-11-08 15:42:31 +08:00
|
|
|
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()
|
2022-10-09 23:35:24 +08:00
|
|
|
if err != nil {
|
2022-11-08 15:42:31 +08:00
|
|
|
return string(stderr.Bytes()), err
|
2022-10-09 23:35:24 +08:00
|
|
|
}
|
2022-11-08 15:42:31 +08:00
|
|
|
return string(stdout.Bytes()), nil
|
2022-10-09 23:35:24 +08:00
|
|
|
}
|