V2bX/common/exec/exec.go

26 lines
483 B
Go
Raw Normal View History

package exec
2023-05-23 22:26:14 -04:00
import (
"errors"
"os"
"os/exec"
)
func RunCommandByShell(cmd string) (string, error) {
2023-05-23 22:26:14 -04:00
e := exec.Command("bash", "-c", cmd)
out, err := e.CombinedOutput()
if errors.Unwrap(err) == exec.ErrNotFound {
e = exec.Command("sh", "-c", cmd)
out, err = e.CombinedOutput()
}
return string(out), err
}
func RunCommandStd(name string, args ...string) {
2023-05-23 22:26:14 -04:00
e := exec.Command(name, args...)
e.Stdout = os.Stdout
e.Stdin = os.Stdin
e.Stderr = os.Stderr
_ = e.Run()
}