diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 91374aa15..6a2b96ddd 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -905,6 +905,7 @@ func moveFileToPath(filepath string, installLocation string) (string, error) { p := os.Getenv("PATH") if !strings.Contains(strings.ToLower(p), strings.ToLower(destDir)) { + utils.FixCommandWithApostrophe(&destDir) pathCmd := "[System.Environment]::SetEnvironmentVariable('Path',[System.Environment]::GetEnvironmentVariable('Path','user') + '" + fmt.Sprintf(";%s", destDir) + "', 'user')" _, err := utils.RunCmdAndWait("powershell", pathCmd) if err != nil { diff --git a/utils/utils.go b/utils/utils.go index 6a4d3aa3b..a65d21728 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -403,3 +403,18 @@ func FindFileInDir(dirPath, fileName string) (string, error) { } return filePath, nil } + +// FixCommandWithApostrophe corrects the passed command which might have apostrophes in it +func FixCommandWithApostrophe(destDir *string) { + bytes := []byte(*destDir) + var result []byte + + for i := 0; i < len(bytes); i++ { + result = append(result, bytes[i]) + if bytes[i] == '\'' { + result = append(result, '\'') + } + } + + *destDir = string(result) +}