m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 23:33:39 -05:00

Fix ExecCommandWith for cmd.exe in Windows (#1072)

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

This commit also updates quoteEntry to use strings.Replace instead of
strconv.Quote which escapes more than \ and ".
This commit is contained in:
Jan Edmund Lazo
2017-10-02 11:36:19 -04:00
committed by Junegunn Choi
parent 0580fe9046
commit c4185e81e8
3 changed files with 36 additions and 8 deletions

View File

@@ -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