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

Failed to parse past path entries on D: #56

Open
johnkazer opened this issue Apr 21, 2018 · 1 comment
Open

Failed to parse past path entries on D: #56

johnkazer opened this issue Apr 21, 2018 · 1 comment
Labels

Comments

@johnkazer
Copy link

johnkazer commented Apr 21, 2018

I have two path entries 'D:....' but whichSync failed to iterate over pathEnv beyond these when trying to find the 'git' path. I changed the order so the 'D:...' entries were last and whichSync parsed everything up to but not including those moved 'D:...' entries. When moved, there were the 14th and 15th path entries.

Didn't work:
image

Worked:
image

@Alhadis
Copy link

Alhadis commented Jun 17, 2018

@johnkazer Just out of curiosity, what's the output you get if you run the following script?

node that-script-below.js
"use strict";

which("git").then(output => {
	console.log(output);
});

/**
 * Locate a program file in the user's $PATH.
 *
 * If found, the returned {@link Promise} resolves to the absolute
 * pathname of the named executable. Otherwise, it resolves to the
 * empty string. Rejects with an error if the execution failed.
 *
 * @example which("curl") == "/usr/bin/curl"
 * @example which("nada") == ""
 * @param {String} name
 * @return {Promise}
 */
function which(name){
	return new Promise((resolve, reject) => {
		if(!name) return resolve("");
		const {exec} = require("child_process");
		const cmdStr = "win32" === process.platform
			? `@for %g in (ECHO ${name.replace(/%/g, "%%")}) do`
				+ " @for %e in (%PATHEXT%) do"
				+ " @for %i in (%g%e) do "
				+ ' @if NOT "%~$PATH:i"=="" echo %~$PATH:i'
			: `command -v '${name.replace(/'/g, `'"'"'`)}' 2>/dev/null`;
		exec(cmdStr, {windowsHide: true}, (error, output) => error
			? reject(error)
			: resolve(output.split(/\r?\n/).filter(Boolean)[0] || ""));
	});
}

@lukekarrys lukekarrys added the bug label Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants