func setOutputRedirect()

in plugin/step/command/command.go [123:154]


func setOutputRedirect(output map[string]string, cmd *exec.Cmd) (*exec.Cmd, *os.File, *os.File, error) {
	var mw io.Writer
	var outFile *os.File
	var errFile *os.File
	var err error
	filePath := output["out"]
	errFilePath := output["err"]
	if filePath != "" {
		mw, outFile, err = setOutputWrite(filePath)
		if err != nil {
			return nil, nil, nil, err
		}
		cmd.Stdout = mw
		if errFilePath == filePath {
			cmd.Stderr = cmd.Stdout
		}
	} else {
		outFile = nil
		cmd.Stdout = os.Stdout
	}
	if filePath != errFilePath && errFilePath != "" {
		mw, errFile, err = setOutputWrite(errFilePath)
		if err != nil {
			return nil, nil, nil, err
		}
		cmd.Stderr = mw
	} else {
		errFile = nil
		cmd.Stderr = os.Stderr
	}
	return cmd, outFile, errFile, nil
}