Skip to content

Commit

Permalink
improved exec.Sudo()
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Oct 26, 2024
1 parent 49e2b83 commit c19a39b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/exec/sudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"syscall"

"gopkg.in/hedzr/errors.v3"

"github.com/hedzr/is"
)

// Run runs an OS command
Expand All @@ -23,6 +25,11 @@ func Run(command string, arguments ...string) (err error) {

// Sudo runs an OS command with sudo prefix
func Sudo(command string, arguments ...string) (retCode int, stdoutText string, err error) {
if is.Root() {
retCode, stdoutText, err = RunCommand(command, true, arguments...)
return
}

var sudocmd string
sudocmd, err = exec.LookPath("sudo")
if err != nil {
Expand Down

0 comments on commit c19a39b

Please sign in to comment.