package common

import (
	"errors"
	"os"
	"os/exec"
)

func RunCommandByBash(cmd string) (string, error) {
	e := exec.Command("bash", "-c", cmd)
	out, err := e.CombinedOutput()
	if errors.Is(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) error {
	e := exec.Command(name, args...)
	e.Stdout = os.Stdout
	e.Stdin = os.Stdin
	e.Stderr = os.Stderr
	return e.Run()
}
