From 0d7234e8b45bc9f712bb9ba7e813749281a8cc87 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 2 Oct 2017 11:36:19 -0400 Subject: [PATCH] Fix ExecCommandWith for cmd.exe in Windows 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 https://github.com/neovim/neovim/pull/7343#issuecomment-333350201 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. --- src/util/util_windows.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util/util_windows.go b/src/util/util_windows.go index 493f4d7fe4f..86409fde80f 100644 --- a/src/util/util_windows.go +++ b/src/util/util_windows.go @@ -6,8 +6,6 @@ import ( "os" "os/exec" "syscall" - - "github.com/mattn/go-shellwords" ) // ExecCommand executes the given command with cmd @@ -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