add env to exec

This commit is contained in:
wh1te909 2022-09-11 01:34:04 +00:00
parent 89d7ec8242
commit e8c743c197

View File

@ -205,6 +205,7 @@ type CmdOptions struct {
IsScript bool IsScript bool
IsExecutable bool IsExecutable bool
Detached bool Detached bool
Env []string
} }
func (a *Agent) NewCMDOpts() *CmdOptions { func (a *Agent) NewCMDOpts() *CmdOptions {
@ -228,11 +229,16 @@ func (a *Agent) CmdV2(c *CmdOptions) CmdStatus {
// have a child process that is in a different process group so that // have a child process that is in a different process group so that
// parent terminating doesn't kill child // parent terminating doesn't kill child
if c.Detached { if c.Detached {
cmdOptions.BeforeExec = []func(cmd *exec.Cmd){ cmdOptions.BeforeExec = append(cmdOptions.BeforeExec, func(cmd *exec.Cmd) {
func(cmd *exec.Cmd) {
cmd.SysProcAttr = SetDetached() cmd.SysProcAttr = SetDetached()
}, })
} }
if len(c.Env) > 0 {
cmdOptions.BeforeExec = append(cmdOptions.BeforeExec, func(cmd *exec.Cmd) {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, c.Env...)
})
} }
var envCmd *gocmd.Cmd var envCmd *gocmd.Cmd