Runs the CLI but returns raw byte output for stdout and stderr. Typically you want to call runExecutable which returns strings instead
(executable string, args []string, workingDirectory string, environment []string)
| 78 | |
| 79 | // Runs the CLI but returns raw byte output for stdout and stderr. Typically you want to call runExecutable which returns strings instead |
| 80 | func runExecutableRawOutput(executable string, args []string, workingDirectory string, environment []string) (stdout []byte, stderr []byte, err error) { |
| 81 | cmd := exec.Command(executable, args...) |
| 82 | cmd.Dir = workingDirectory |
| 83 | // don't hook stdin, go isn't going to ask us for anything |
| 84 | stdIn, _ := cmd.StdinPipe() |
| 85 | stdOut, _ := cmd.StdoutPipe() |
| 86 | stdErr, _ := cmd.StderrPipe() |
| 87 | |
| 88 | if environment != nil { |
| 89 | cmd.Env = environment |
| 90 | } |
| 91 | |
| 92 | err = cmd.Start() |
| 93 | if err != nil { |
| 94 | return |
| 95 | } |
| 96 | err = stdIn.Close() |
| 97 | if err != nil { |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | stdout, _ = io.ReadAll(stdOut) |
| 102 | stderr, _ = io.ReadAll(stdErr) |
| 103 | |
| 104 | err = cmd.Wait() // wait for exit |
| 105 | |
| 106 | // note! If the process returned an exit code, then err will be an exec.ExitError |
| 107 | // but stdout and stderr strings may have data in them that may be interesting. |
| 108 | return |
| 109 | } |
| 110 | |
| 111 | // EnsureCli builds the CLI using 'go build' if it does not already exist. |
| 112 | // note: this will always deliberately build the CLI the first time you invoke it, just in case |
no test coverage detected