summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRashil Gandhi <rashil2000@gmail.com>2021-10-27 13:20:40 +0530
committerJunegunn Choi <junegunn.c@gmail.com>2021-11-02 15:56:20 +0900
commit7c3f42bbbaf06a9dfabf50585de54d5e675992be (patch)
tree7fbbba5e29f3b571010c7601b80cb27543b70056
parentedac9820b54d8db7ef667c2d79b9e526c625f59d (diff)
Fix powershell escaping
-rw-r--r--src/terminal_windows.go2
-rw-r--r--src/util/util_windows.go18
2 files changed, 10 insertions, 10 deletions
diff --git a/src/terminal_windows.go b/src/terminal_windows.go
index 7ba64dff..5e748733 100644
--- a/src/terminal_windows.go
+++ b/src/terminal_windows.go
@@ -37,7 +37,7 @@ func quoteEntry(entry string) string {
return "^" + match
})
} else if strings.Contains(shell, "pwsh") || strings.Contains(shell, "powershell") {
- escaped := strings.Replace(entry, `"`, `""`, -1)
+ escaped := strings.Replace(entry, `"`, `\"`, -1)
return "'" + strings.Replace(escaped, "'", "''", -1) + "'"
} else {
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
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