mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
26 lines
483 B
Go
26 lines
483 B
Go
package exec
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
func RunCommandByShell(cmd string) (string, error) {
|
|
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) {
|
|
e := exec.Command(name, args...)
|
|
e.Stdout = os.Stdout
|
|
e.Stdin = os.Stdin
|
|
e.Stderr = os.Stderr
|
|
_ = e.Run()
|
|
}
|