Os Exec Sudo Command in Go

后端 未结 1 2075
广开言路
广开言路 2021-02-07 18:56

In the process of familiarizing myself with Go and goroutines I have hit a road block with executing commands. The format of these commands are:

sudo find /folde         


        
相关标签:
1条回答
  • 2021-02-07 19:25

    exec.Command() will ask the kernel to execute the given process directly. However, the command you are passing is a string of multiple programs hooked together by a shell script.

    If you want to execute a shell script, you should use something like this:

    cmd := exec.Command("/bin/sh", "-c", "sudo find ...")
    
    0 讨论(0)
提交回复
热议问题