From 3b7c0ffbe6f403dc4d4d2d62a12357204cfd7dae Mon Sep 17 00:00:00 2001 From: Matt LaPlante Date: Fri, 1 Jul 2022 10:34:19 -0700 Subject: [PATCH] Fully qualify the path to powershell.exe due to https://github.com/golang/go/issues/53536 PiperOrigin-RevId: 458498623 --- powershell/powershell_windows.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/powershell/powershell_windows.go b/powershell/powershell_windows.go index 3518464..fc9e735 100644 --- a/powershell/powershell_windows.go +++ b/powershell/powershell_windows.go @@ -20,12 +20,16 @@ package powershell import ( "encoding/json" "fmt" + "os" "os/exec" + "path/filepath" ) var ( // Dependency injection for testing. powerShellCmd = powerShell + + powerShellExe = filepath.Join(os.Getenv("SystemRoot"), `\System32\WindowsPowerShell\v1.0\powershell.exe`) ) // powerShell represents the OS command used to run a powerShell cmdlet on @@ -34,9 +38,9 @@ var ( // parameters to invoke powershell.exe from the command line. If an error is // returne to the OS, it will be returned here. func powerShell(params []string) ([]byte, error) { - out, err := exec.Command("powershell.exe", params...).CombinedOutput() + out, err := exec.Command(powerShellExe, params...).CombinedOutput() if err != nil { - return []byte{}, fmt.Errorf(`exec.Command("powershell.exe", %s) command returned: %q: %v`, params, out, err) + return []byte{}, fmt.Errorf(`exec.Command(%q, %s) command returned: %q: %v`, powerShellExe, params, out, err) } return out, nil }