fleet/tools/github-manage/pkg/ghapi/cli.go
George Karr df5e42a54c
Github Manager (#31540)
New tool to help with github management. Read all about it in the
[README](https://github.com/fleetdm/fleet/blob/gkarr-gm/tools/github-manage/README.md)
on this branch.
2025-08-07 15:00:36 -05:00

23 lines
543 B
Go

package ghapi
import (
"bytes"
"os/exec"
"fleetdm/gm/pkg/logger"
)
// RunCommandAndReturnOutput runs a bash command, captures its output, and returns the output as a byte slice.
func RunCommandAndReturnOutput(command string) ([]byte, error) {
logger.Debugf("Running COMMAND: %s", command)
cmd := exec.Command("bash", "-c", command)
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
if err := cmd.Run(); err != nil {
logger.Errorf("Error running command: %s", out.String())
return nil, err
}
return out.Bytes(), nil
}