Skip to content

Commit

Permalink
Fix execution of command with quotes on windows. (knqyf263#238)
Browse files Browse the repository at this point in the history
Commands with quotes can't be handled on windows using standard
exec.Command() calls. Based on the go documentation
https://pkg.go.dev/os/exec#Command the argument handling is converted
to SysProcAttr.
  • Loading branch information
matrixx567 authored Jan 23, 2024
1 parent 4304034 commit 4c51204
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"runtime"
"strings"
"syscall"

"github.com/fatih/color"
"github.com/knqyf263/pet/config"
Expand All @@ -26,7 +27,8 @@ func run(command string, r io.Reader, w io.Writer) error {
line := append(config.Conf.General.Cmd, command)
cmd = exec.Command(line[0], line[1:]...)
} else if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/c", command)
cmd = exec.Command("cmd.exe")
cmd.SysProcAttr = &syscall.SysProcAttr{CmdLine: fmt.Sprintf("/c \"%s\"", command)}
} else {
cmd = exec.Command("sh", "-c", command)
}
Expand Down

0 comments on commit 4c51204

Please sign in to comment.