initial commit
This commit is contained in:
34
tplCmd/funcs_cmd.go
Normal file
34
tplCmd/funcs_cmd.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package tplCmd
|
||||
|
||||
import (
|
||||
`os`
|
||||
`os/exec`
|
||||
)
|
||||
|
||||
/*
|
||||
ToCmd returns an (os/)exec.Cmd from a Cmd.
|
||||
|
||||
err will always be nil for now, but is still returned and should be handled
|
||||
for future-proofing.
|
||||
*/
|
||||
func (c *Cmd) ToCmd() (cmd *exec.Cmd, err error) {
|
||||
|
||||
var envs []string
|
||||
|
||||
if c.Args != nil && len(c.Args) > 0 {
|
||||
cmd = exec.Command(c.Program, c.Args...)
|
||||
} else {
|
||||
cmd = exec.Command(c.Program)
|
||||
}
|
||||
|
||||
if !c.IsolateEnv {
|
||||
envs = os.Environ()
|
||||
}
|
||||
if c.EnvVars != nil && len(c.EnvVars) > 0 {
|
||||
envs = append(envs, c.EnvVars...)
|
||||
}
|
||||
|
||||
cmd.Env = envs
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user