Risabh Sharma
Risabh Sharma

Reputation: 654

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

Upvotes: 1

Views: 5315

Answers (1)

William Tohmson
William Tohmson

Reputation: 94

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)
    }

Upvotes: 2

Related Questions