Hi,
    I need to execute a couple of commands in golang, the code is roughly 
as below,

   cmd := exec.Command(executable, newArgs...)

   if env != nil && len(env) > 0 {

       cmd.Env = env

   }

   outMsg, err := cmd.CombinedOutput()

   if err != nil {
       ......

   }

   Executing the commands need root privileges, so it works when I start 
the golang program using "sudo ./gobinary".  But the golang program is 
supposed to run inside a container, so it isn't good to run the container 
using root. Then I tried to use "sudo" to execute the command, but the 
environment variables can't be carried over into the command; In other 
words, once I use "sudo" to execute the commands, then the environment 
variables are lost.  

   Do anyone have any suggestions on this? Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cbc4506b-2be7-4acc-824f-ed26ae9707a6%40googlegroups.com.

Reply via email to