Comments (1)
@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] || ""));
});
}
from node-which.
Related Issues (20)
- [BUG] `process.env.PATH` can be undefined on Windows
- 'node-which' is not recognized... HOT 1
- Antivirus/Malware report HOT 8
- Windows tests fail on linux because writing to process.env is implicitly converted to a string HOT 2
- which sync cannot work on windows HOT 1
- [Windows] File extension always in capital letters HOT 1
- Error: Cannot find module '../' HOT 3
- Resolving paths wrong in git bash on windows HOT 1
- Feature request: option to avoid throwing in whichSync HOT 1
- cannot install HOT 2
- Doesn't find executables in case-sensitive directory on Windows
- 160x slower than GNU which (~500ms vs. 3ms) HOT 3
- Support modern async/Promise usage
- Does not install under raspberry pi (arm32) HOT 4
- [BUG] Callback is part of promise chain HOT 2
- npm which function fails to get full path to an executable in macOS within an Electron app running in production mode but, works fine in development mode HOT 5
- [FEATURE] nothrow option for async which HOT 2
- [FEATURE] command -v is preferable (usually) to which HOT 3
- [BUG] Unable to invoke `which` from Windows 11's Terminal HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-which.