gitforgefs/utils/process.go

30 lines
610 B
Go
Raw Normal View History

package utils
import (
2024-06-06 05:51:34 +00:00
"log/slog"
"os/exec"
"strings"
)
const (
stdout = "stdout"
stderr = "stderr"
)
2024-06-06 05:51:34 +00:00
func ExecProcessInDir(logger *slog.Logger, workdir string, command string, args ...string) (string, error) {
cmd := exec.Command(command, args...)
if workdir != "" {
cmd.Dir = workdir
}
// Run the command
2024-06-06 05:51:34 +00:00
logger.Debug("Running command", "cmd", command, "args", args)
output, err := cmd.Output()
return strings.TrimSpace(string(output)), err
}
2024-06-06 05:51:34 +00:00
func ExecProcess(logger *slog.Logger, command string, args ...string) (string, error) {
return ExecProcessInDir(logger, "", command, args...)
}