From 3b398d4aecd2e9939197a9f4f87106337c3a9f37 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sun, 18 Jun 2023 00:07:53 +1000 Subject: [PATCH] Improve windows shell handling --- os_windows.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/os_windows.go b/os_windows.go index ff9ac4bd..8e3740e3 100644 --- a/os_windows.go +++ b/os_windows.go @@ -101,11 +101,16 @@ func detachedCommand(name string, arg ...string) *exec.Cmd { } func shellCommand(s string, args []string) *exec.Cmd { - args = append([]string{gOpts.shellflag, s}, args...) + var builder strings.Builder + builder.WriteString(s) + for _, arg := range args { + fmt.Fprintf(&builder, ` "%s"`, arg) + } + cmdline := fmt.Sprintf(`%s %s "%s"`, gOpts.shellopts, gOpts.shellflag, builder.String()) - args = append(gOpts.shellopts, args...) - - return exec.Command(gOpts.shell, args...) + cmd := exec.Command(gOpts.shell) + cmd.SysProcAttr = &windows.SysProcAttr{CmdLine: cmdline} + return cmd } func shellSetPG(cmd *exec.Cmd) {