From 6c175fabaf663631d5085b01d66bf16dfa9e0f1c Mon Sep 17 00:00:00 2001 From: Harald Fassler Date: Sat, 15 Apr 2023 12:36:21 +0200 Subject: [PATCH] fix issue #932 Signed-off-by: Harald Fassler --- src/nvm.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/nvm.go b/src/nvm.go index 9c156699..f148962e 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -1163,16 +1163,19 @@ func updateRootDir(path string) { } func elevatedRun(name string, arg ...string) (bool, error) { - ok, err := run("cmd", append([]string{"/C", name}, arg...)...) + ok, err := run("cmd", nil, append([]string{"/C", name}, arg...)...) if err != nil { - ok, err = run(filepath.Join(env.root, "elevate.cmd"), append([]string{"cmd", "/C", name}, arg...)...) + ok, err = run("elevate.cmd", &env.root, append([]string{"cmd", "/C", name}, arg...)...) } return ok, err } -func run(name string, arg ...string) (bool, error) { +func run(name string, dir *string, arg ...string) (bool, error) { c := exec.Command(name, arg...) + if dir != nil { + c.Dir = *dir + } var stderr bytes.Buffer c.Stderr = &stderr err := c.Run()