FIX #639 and #510 find powershell.exe

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-12-23 11:56:40 +01:00
parent fa8fa69e7c
commit 22cf29b2ee
2 changed files with 9 additions and 10 deletions

View File

@ -130,6 +130,11 @@ func (d *Driver) GetState() (state.State, error) {
// PreCreateCheck checks that the machine creation process can be started safely.
func (d *Driver) PreCreateCheck() error {
// Check that powershell was found
if powershell == "" {
return ErrPowerShellNotFound
}
// Check that hyperv is installed
if err := hypervAvailable(); err != nil {
return err

View File

@ -4,9 +4,7 @@ import (
"bufio"
"bytes"
"errors"
"os"
"os/exec"
"path/filepath"
"strings"
"fmt"
@ -17,17 +15,13 @@ import (
var powershell string
var (
ErrNotAdministrator = errors.New("Hyper-v commands have to be run as an Administrator")
ErrNotInstalled = errors.New("Hyper-V PowerShell Module is not available")
ErrPowerShellNotFound = errors.New("Powershell was not found in the path")
ErrNotAdministrator = errors.New("Hyper-v commands have to be run as an Administrator")
ErrNotInstalled = errors.New("Hyper-V PowerShell Module is not available")
)
func init() {
systemPath := strings.Split(os.Getenv("PATH"), ";")
for _, path := range systemPath {
if strings.Index(path, "WindowsPowerShell") != -1 {
powershell = filepath.Join(path, "powershell.exe")
}
}
powershell, _ = exec.LookPath("powershell.exe")
}
func cmdOut(args ...string) (string, error) {