1

I am trying to execute a python script ( which is used for accessing remote machines and run commands ) from Golang, it errors with "exit status 2"

out, err := exec.Command("/usr/local/opt/bin/python3.7", "/users/test.py -i 12.13.14.15 --cmd \"uptime && date\"").Output()


if err != nil {
    fmt.Printf("%s", err)
} else {
    fmt.Println("Command Successfully Executed")
    output := string(out[:])
    fmt.Println(output)
}

Output

exit status 2

thank you.

1 Answer 1

1

You are passing a single argument to the executable containing everything. Instead, you have to pass each argument separately:

out, err := exec.Command("/usr/local/opt/bin/python3.7", "/users/test.py", "-i", "12.13.14.15", "--cmd", "uptime && date").Output()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.