Skip to content

Commit bc59b8a

Browse files
authored
Merge pull request #273 from typeless/master
modules/process: add ExecDirEnv (next to ExecDir)
2 parents 3ac7225 + 9aaf2a6 commit bc59b8a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/process/manager.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ func Add(desc string, cmd *exec.Cmd) int64 {
5252
return pid
5353
}
5454

55-
// ExecDir runs a command in given path and waits for its completion
55+
// ExecDirEnv runs a command in given path and environment variables, and waits for its completion
5656
// up to the given timeout (or DefaultTimeout if -1 is given).
5757
// Returns its complete stdout and stderr
5858
// outputs and an error, if any (including timeout)
59-
func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) {
59+
func ExecDirEnv(timeout time.Duration, dir, desc string, env []string, cmdName string, args ...string) (string, string, error) {
6060
if timeout == -1 {
6161
timeout = DefaultTimeout
6262
}
@@ -66,6 +66,7 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
6666

6767
cmd := exec.Command(cmdName, args...)
6868
cmd.Dir = dir
69+
cmd.Env = env
6970
cmd.Stdout = bufOut
7071
cmd.Stderr = bufErr
7172
if err := cmd.Start(); err != nil {
@@ -93,6 +94,11 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
9394
return bufOut.String(), bufErr.String(), err
9495
}
9596

97+
// ExecDir works exactly like ExecDirEnv except no environment variable is provided.
98+
func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) {
99+
return ExecDirEnv(timeout, dir, desc, nil, cmdName, args...)
100+
}
101+
96102
// ExecTimeout runs a command and waits for its completion
97103
// up to the given timeout (or DefaultTimeout if -1 is given).
98104
// Returns its complete stdout and stderr

0 commit comments

Comments
 (0)