Skip to content

Commit

Permalink
Fix powershell escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
rashil2000 authored and junegunn committed Nov 2, 2021
1 parent edac982 commit 7c3f42b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/terminal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) + "'"
Expand Down
18 changes: 9 additions & 9 deletions src/util/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c3f42b

Please sign in to comment.