Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces in installation path are properly handled by nvm install, but not by nvm use #932

Closed
janerjak opened this issue Feb 14, 2023 · 8 comments · Fixed by #965
Closed
Labels
Stale Stale

Comments

@janerjak
Copy link

Issue:
When installing nvm-windows using the nvm-setup.exe to a path with spaces, e.g. "C:\Programs X", the command nvm install latest successfully runs. nvm use latest will return a non-zero exit-code and produce the output
exit status 1: 'C:\Programs' is not recognized as an internal or external command, operable program or batch file.

How To Reproduce:

  1. Install nvm using nvm-setup.exe (version 1.1.1.0, launched with admin privileges) to a path containing spaces
  2. Open a terminal window and type nvm install latest (this should work)
  3. Type nvm use latest
  4. See error

Expected Behavior:
nvm selecting the correct version

Screenshots:
image

Notes: The screenshot is taken from a terminal running MINGW64. The bug is also present in Command Line (Windows 11) and Power Shell.

Desktop:

  • OS: Windows 11 22H2
@iquanxin
Copy link

Check your environment PATH

@janerjak
Copy link
Author

Check your environment PATH

Sorry, what exactly should I check? Installing at a path without spaces works like a charm (which I ultimately did).

Nevertheless, this should be fixed at some point.

@Plagiatus
Copy link

Plagiatus commented Feb 20, 2023

Having the same issue on Win10 Pro Build 19044, using nvm 1.1.10. Possibly related to #355 ?

@lava-floor
Copy link

Hi, I've encountered the same issue; solved running cmd as Administrator

@github-actions github-actions bot added the Stale Stale label Mar 24, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2023
@coreybutler coreybutler reopened this Mar 31, 2023
Repository owner deleted a comment from github-actions bot Mar 31, 2023
Repository owner deleted a comment from github-actions bot Mar 31, 2023
@github-actions github-actions bot removed the Stale Stale label Apr 1, 2023
@nineninesevenfour
Copy link
Contributor

I suggest to fix it by wrapping arguments with an escape function in nvm.go:

func run(name string, arg ...string) (bool, error) {
	c := exec.Command(name, escape(arg)...)
	// ... rest of function
}

func escape(args []string) []string {
	for index, arg := range args {
		if strings.Contains(arg, " ") && !strings.HasPrefix(arg, "\"") {
			args[index] = "\"" + arg + "\""
		}
	}
	return args
}

As far as I have seen this should work with current usages, but I did not test it.

nineninesevenfour added a commit to nineninesevenfour/nvm-windows that referenced this issue Apr 15, 2023
Signed-off-by: Harald Fassler <harald.fassler+9974@gmail.com>
@nineninesevenfour
Copy link
Contributor

It turned out, that spaces in the arguments was not the problem. The problem was that exec.Command(...) refuses to execute commands with spaces in it. Quoting the command did not work as well. But setting Dir in type Cmd worked.
PR follows.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Stale label May 16, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants