mirror of
https://github.com/go-gitea/gitea
synced 2024-12-25 11:14:52 +01:00
Merge pull request #273 from typeless/master
modules/process: add ExecDirEnv (next to ExecDir)
This commit is contained in:
commit
bc59b8abc9
1 changed files with 8 additions and 2 deletions
|
@ -52,11 +52,11 @@ func Add(desc string, cmd *exec.Cmd) int64 {
|
||||||
return pid
|
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).
|
// up to the given timeout (or DefaultTimeout if -1 is given).
|
||||||
// Returns its complete stdout and stderr
|
// Returns its complete stdout and stderr
|
||||||
// outputs and an error, if any (including timeout)
|
// 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 {
|
if timeout == -1 {
|
||||||
timeout = DefaultTimeout
|
timeout = DefaultTimeout
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
|
||||||
|
|
||||||
cmd := exec.Command(cmdName, args...)
|
cmd := exec.Command(cmdName, args...)
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
|
cmd.Env = env
|
||||||
cmd.Stdout = bufOut
|
cmd.Stdout = bufOut
|
||||||
cmd.Stderr = bufErr
|
cmd.Stderr = bufErr
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
|
@ -93,6 +94,11 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
|
||||||
return bufOut.String(), bufErr.String(), err
|
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
|
// ExecTimeout runs a command and waits for its completion
|
||||||
// up to the given timeout (or DefaultTimeout if -1 is given).
|
// up to the given timeout (or DefaultTimeout if -1 is given).
|
||||||
// Returns its complete stdout and stderr
|
// Returns its complete stdout and stderr
|
||||||
|
|
Loading…
Reference in a new issue