Skip to content

modules/process: add ExecDirEnv (next to ExecDir) #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions modules/process/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func Add(desc string, cmd *exec.Cmd) int64 {
return pid
}

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

cmd := exec.Command(cmdName, args...)
cmd.Dir = dir
cmd.Env = env
cmd.Stdout = bufOut
cmd.Stderr = bufErr
if err := cmd.Start(); err != nil {
Expand Down Expand Up @@ -93,6 +94,11 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
return bufOut.String(), bufErr.String(), err
}

// ExecDir works exactly like ExecDirEnv except no environment variable is provided.
func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) {
return ExecDirEnv(timeout, dir, desc, nil, cmdName, args...)
}

// ExecTimeout runs a command and waits for its completion
// up to the given timeout (or DefaultTimeout if -1 is given).
// Returns its complete stdout and stderr
Expand Down