简体   繁体   中英

How do I run shell command in golang

I have a shell command

set -a  source /etc/environment; set +a

I want to run this command to refresh my env file

the code I tried to do

cmd, err := exec.Command("bash", "set -a  source /etc/environment; set +a").Output()
    fmt.Println("cmd=================>", cmd)

    if err != nil {
        fmt.Println(err)
    }

it gave me exit status 127

try this

cmd, err := exec.Command("bash","-c", "set -a  source /etc/environment; set +a").Output()
    fmt.Println("cmd=================>", cmd)

    if err != nil {
        fmt.Println(err)
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM