fix: wait for command to complete

without wait(), the *ProcessState is nil, meaning we can't access
the ExitCode(). On Windows, calling wait() introduces a timeout
which makes things run slower, which is why we only call wait()
in case of an error. That should not be the main use-case.

relates to #285
This commit is contained in:
Jan De Dobbeleer 2020-12-31 13:21:14 +01:00 committed by Jan De Dobbeleer
parent 7e7483501c
commit d9d2430ae9

View file

@ -201,6 +201,9 @@ func (env *environment) runCommand(command string, args ...string) (string, erro
stdoutString := getOutputString(stdout)
stderrString := getOutputString(stderr)
if stderrString != "" {
// only wait in case of error reduces the lead time on successful
// commands on windows due to not calling process.Wait()
_ = cmd.Wait()
return "", &commandError{
err: stderrString,
exitCode: cmd.ProcessState.ExitCode(),