RunHostCommandWithOptions executes a command on the host with configurable options and returns the combined stdout/stderr results and error
(command string, options []CmdOption, args ...string)
| 151 | // RunHostCommandWithOptions executes a command on the host with configurable options |
| 152 | // and returns the combined stdout/stderr results and error |
| 153 | func RunHostCommandWithOptions(command string, options []CmdOption, args ...string) (string, error) { |
| 154 | if globalconfig.DdevVerbose { |
| 155 | output.UserOut.Printf("RunHostCommandWithOptions: %s %s", command, strings.Join(args, " ")) |
| 156 | } |
| 157 | c := HostCommand(command, args...) |
| 158 | |
| 159 | // Apply all options |
| 160 | for _, option := range options { |
| 161 | option(c) |
| 162 | } |
| 163 | // Default to os.Stdin if no stdin was set |
| 164 | if c.Stdin == nil { |
| 165 | c.Stdin = os.Stdin |
| 166 | } |
| 167 | |
| 168 | o, err := c.CombinedOutput() |
| 169 | if globalconfig.DdevVerbose { |
| 170 | output.UserOut.Printf("RunHostCommandWithOptions returned output=%v err=%v", string(o), err) |
| 171 | } |
| 172 | |
| 173 | return string(o), err |
| 174 | } |
| 175 | |
| 176 | // RunHostCommandSeparateStreams executes a command on the host and returns the |
| 177 | // stdout and error |