execCommand executes the bash command and returns the (output, error) from command, error if timeout occurs.
(timeout time.Duration, command string, args ...string)
| 186 | |
| 187 | // execCommand executes the bash command and returns the (output, error) from command, error if timeout occurs. |
| 188 | func execCommand(timeout time.Duration, command string, args ...string) (string, error) { |
| 189 | ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| 190 | defer cancel() |
| 191 | cmd := exec.CommandContext(ctx, command, args...) |
| 192 | out, err := cmd.CombinedOutput() |
| 193 | if err != nil { |
| 194 | klog.Infof("command %v failed: %v, %s\n", cmd, err, string(out)) |
| 195 | return "", err |
| 196 | } |
| 197 | |
| 198 | return strings.TrimSuffix(string(out), "\n"), nil |
| 199 | } |
no outgoing calls
no test coverage detected