ExecuteCommandOutput runs the command and returns its combined standard output and standard error.
(cmd *exec.Cmd, pathPrefix string, envars []string)
| 121 | // ExecuteCommandOutput runs the command and returns its |
| 122 | // combined standard output and standard error. |
| 123 | func ExecuteCommandOutput(cmd *exec.Cmd, pathPrefix string, envars []string) string { |
| 124 | |
| 125 | cmd.Dir = pathPrefix |
| 126 | if !filepath.IsAbs(pathPrefix) { |
| 127 | dir := GetCwd() |
| 128 | cmd.Dir = path.Join(dir, pathPrefix) |
| 129 | } |
| 130 | |
| 131 | cmd.Env = os.Environ() |
| 132 | if envars != nil { |
| 133 | cmd.Env = append(os.Environ(), envars...) |
| 134 | } |
| 135 | |
| 136 | out, err := cmd.CombinedOutput() |
| 137 | if err != nil { |
| 138 | log.Fatalf("Executing command with output failed: (%v) %s\n", err, out) |
| 139 | } |
| 140 | return string(out) |
| 141 | } |
| 142 | |
| 143 | // AppendProjectEnvToCmdEnv converts a key-value pair map into a slice of `key=value`s |
| 144 | // allow module definition to use an alternative env-var-name than field while apply |