Skip to content

Commit

Permalink
run command windows
Browse files Browse the repository at this point in the history
  • Loading branch information
markovichecha authored and mrexox committed Jun 9, 2022
1 parent 6802534 commit 02e6c56
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/lefthook/run_command_windows.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 02e6c56

Please sign in to comment.