MCPcopy Index your code
hub / github.com/commitdev/zero / ExecuteCommandOutput

Function ExecuteCommandOutput

internal/util/util.go:123–141  ·  view source on GitHub ↗

ExecuteCommandOutput runs the command and returns its combined standard output and standard error.

(cmd *exec.Cmd, pathPrefix string, envars []string)

Source from the content-addressed store, hash-verified

121// ExecuteCommandOutput runs the command and returns its
122// combined standard output and standard error.
123func 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

Callers

nothing calls this directly

Calls 1

GetCwdFunction · 0.85

Tested by

no test coverage detected