|
|
@ -6,25 +6,17 @@ package externalcmd |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/kballard/go-shellquote" |
|
|
|
"github.com/kballard/go-shellquote" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func (e *Cmd) runInner() (int, bool) { |
|
|
|
func (e *Cmd) runInner() (int, bool) { |
|
|
|
// On Windows, the shell is not used and command is started directly.
|
|
|
|
cmdparts, err := shellquote.Split(e.cmdstr) |
|
|
|
// Variables are replaced manually in order to guarantee compatibility
|
|
|
|
|
|
|
|
// with Linux commands.
|
|
|
|
|
|
|
|
tmp := e.cmdstr |
|
|
|
|
|
|
|
for key, val := range e.env { |
|
|
|
|
|
|
|
tmp = strings.ReplaceAll(tmp, "$"+key, val) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parts, err := shellquote.Split(tmp) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return 0, true |
|
|
|
return 0, true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(parts[0], parts[1:]...) |
|
|
|
cmd := exec.Command(cmdparts[0], cmdparts[1:]...) |
|
|
|
|
|
|
|
|
|
|
|
cmd.Env = append([]string(nil), os.Environ()...) |
|
|
|
cmd.Env = append([]string(nil), os.Environ()...) |
|
|
|
for key, val := range e.env { |
|
|
|
for key, val := range e.env { |
|
|
|