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

which sync cannot work on windows #47

Closed
young-mu opened this issue Apr 19, 2017 · 1 comment
Closed

which sync cannot work on windows #47

young-mu opened this issue Apr 19, 2017 · 1 comment

Comments

@young-mu
Copy link

young-mu commented Apr 19, 2017

In Git Bash on Windows 10

$ which esptool.py
/c/Python27/Scripts/esptool.py

c:/Python27/Scripts is also added in PATH ENV.

But, the following code using which module is failed.

var which = require('which');
var cmd = 'esptool.py';

try {
    var ret = which.sync(cmd);
} catch (error) {
    console.log('error', error);
}

console.log(ret);
$ node test.js
error { Error: not found: esptool.py
    at getNotFoundError (C:\Users\Young\Desktop\test\node_modules\which\which.js:13:12)
    at Function.whichSync [as sync] (C:\Users\Young\Desktop\test\node_modules\which\which.js:132:9)
    at Object.<anonymous> (C:\Users\Young\Desktop\test\test.js:6:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7) code: 'ENOENT' }
undefined

What's wrong ???

@isaacs
Copy link
Contributor

isaacs commented May 16, 2017

My guess is that you don't have .py in your PATHEXT environment variable. Therefor, even though esptool.py might be in the PATH, and have a mode including +x, it isn't executable because Windows systems judge executability based on the path extension. Note that if you ran esptool.py in the cmd.exe terminal, it'll say that it doesn't recognize the command.

bash on windows does not judge executability this way, since it's a ported unix tool that follows unix conventions in most things.

Put .py in your PATHEXT environment variable, and it'll work.

Or you can pass a modified pathExt by doing which.sync('esptool.py', {pathExt: ';' + process.env.PATHEXT}). That works because PATHEXT is colon-delimited, and if there's an entry at the start of it that is '', then it'll allow any command that is fully specified.

I know this is all a bit bonkers if you're more familiar with the Unix way, but it's how Windows works, and the point of this lib is to work out if exec(command) will find a thing or not, and which one it'll find.

@isaacs isaacs closed this as completed May 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants