Skip to content

Commit

Permalink
Fully qualify the path to powershell.exe due to golang/go#53536
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 458498623
  • Loading branch information
ItsMattL authored and copybara-github committed Jul 1, 2022
1 parent 89df70d commit 3b7c0ff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions powershell/powershell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 3b7c0ff

Please sign in to comment.