diff --git a/internal/lefthook/run_command_windows.go b/internal/lefthook/run_command_windows.go new file mode 100644 index 00000000..b9fd0b16 --- /dev/null +++ b/internal/lefthook/run_command_windows.go @@ -0,0 +1,33 @@ +package lefthook + +import ( + "bytes" + "os" + "os/exec" + "path/filepath" + "strings" +) + +func RunCommand(runner string, cmdRoot string) (*bytes.Buffer, bool, error) { + runnerArgs := strings.Split(runner, " ") + command := exec.Command(runnerArgs[0], runnerArgs[1:]...) + if cmdRoot != "" { + fullPath, _ := filepath.Abs(cmdRoot) + command.Dir = fullPath + } + return RunPlainCommand(command) +} + +func RunPlainCommand(command *exec.Cmd) (*bytes.Buffer, bool, error) { + var commandOutput bytes.Buffer + + command.Stdout = &commandOutput + command.Stdin = os.Stdin + command.Stderr = os.Stderr + + err := command.Start() + if err != nil { + return nil, false, err + } + return &commandOutput, true, command.Wait() +}