Skip to content

Commit

Permalink
Fix ExecCommandWith for cmd.exe in Windows
Browse files Browse the repository at this point in the history
Close 1018

Run the command as is in cmd.exe with no parsing and escaping.
Explicity set cmd.SysProcAttr so execCommand does not escape the command.
Technically, the command should be escaped with ^ for special characters, including ".
This allows cmd.exe commands to be chained together.

See neovim/neovim#7343 (comment)

However, this requires a new shellescape function that is specific to one of the following:
- interactive prompt
- batchfile
- command name
fzf#shellescape in the Vim plugin can handle only the batchfile.
  • Loading branch information
janlazo committed Oct 2, 2017
1 parent c261446 commit 921e6c5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/util/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"
"os/exec"
"syscall"

"github.com/mattn/go-shellwords"
)

// ExecCommand executes the given command with cmd
Expand All @@ -18,11 +16,13 @@ func ExecCommand(command string) *exec.Cmd {
// ExecCommandWith executes the given command with cmd. _shell parameter is
// ignored on Windows.
func ExecCommandWith(_shell string, command string) *exec.Cmd {
args, _ := shellwords.Parse(command)
allArgs := make([]string, len(args)+1)
allArgs[0] = "/c"
copy(allArgs[1:], args)
return exec.Command("cmd", allArgs...)
cmd := exec.Command("cmd")
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: false,
CmdLine: fmt.Sprintf(` /s /c "%s"`, command),
CreationFlags: 0,
}
return cmd
}

// IsWindows returns true on Windows
Expand Down

0 comments on commit 921e6c5

Please sign in to comment.