From 7c3f42bbbaf06a9dfabf50585de54d5e675992be Mon Sep 17 00:00:00 2001 From: Rashil Gandhi Date: Wed, 27 Oct 2021 13:20:40 +0530 Subject: Fix powershell escaping --- src/util/util_windows.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/util/util_windows.go') diff --git a/src/util/util_windows.go b/src/util/util_windows.go index 9ac062af..e4e04376 100644 --- a/src/util/util_windows.go +++ b/src/util/util_windows.go @@ -39,24 +39,24 @@ func ExecCommand(command string, setpgid bool) *exec.Cmd { // NOTE: For "powershell", we should ideally set output encoding to UTF8, // but it is left as is now because no adverse effect has been observed. func ExecCommandWith(shell string, command string, setpgid bool) *exec.Cmd { - var commandline string + var cmd *exec.Cmd if strings.Contains(shell, "cmd") { - commandline = fmt.Sprintf(` /v:on/s/c "%s"`, command) - } else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") { - commandline = fmt.Sprintf(` -NoProfile -Command "& { %s }"`, command) - } - if len(commandline) == 0 { - cmd := exec.Command(shell, "-c", command) + cmd = exec.Command(shell) cmd.SysProcAttr = &syscall.SysProcAttr{ HideWindow: false, + CmdLine: fmt.Sprintf(` /v:on/s/c "%s"`, command), CreationFlags: 0, } return cmd } - cmd := exec.Command(shell) + + if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") { + cmd = exec.Command(shell, "-NoProfile", "-Command", command) + } else { + cmd = exec.Command(shell, "-c", command) + } cmd.SysProcAttr = &syscall.SysProcAttr{ HideWindow: false, - CmdLine: commandline, CreationFlags: 0, } return cmd -- cgit v1.2.3