I'm writing a go wrapper for a popular command line tool (ansible-playbook) and I need to pass a parameter through with the exec.Command call. The bash equivalent would be:
MY_VAR=some_value ansible-playbook -i custom-inventory playbook.yml
Previously I was just exporting MY_VAR using os.Setenv, but that causes problems for parallel executions of the playbook. So I want to pass the var in front of the command so that each call has it's own value for this var.
I'm not really sure how to do this with exec.Command since the first parameter to that function is "command". Any tips?
edit: I have tried using the Env field of the Cmd struct but that overrides all environment variables. I have a significant amount of configuration set and I would just like to override this one specific environment variable. Is this not possible??
question from:
https://stackoverflow.com/questions/41133115/pass-env-var-to-exec-command 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…