. , which where, . Windows Posix (Mac, Linux, Unix, Windows, Posix, Posix).
const fs = require('fs');
const path = require('path');
const child = require("child_process");
function getExecPath(exec) {
let result;
try {
result = child.execSync("which " + exec).toString().trim();
} catch(ex) {
try {
result = child.execSync("where " + exec).toString().trim();
} catch(ex2) {
return;
}
}
if (result.toLowerCase().indexOf("command not found") !== -1 ||
result.toLowerCase().indexOf("could not find files") !== -1) {
return;
}
return result;
}
function isExec(exec) {
if (process.platform === "win32") {
switch(Path.GetExtension(exec).toLowerCase()) {
case "exe": case "bat": case "cmd": case "vbs": case "ps1": {
return true;
}
}
}
try {
fs.accessSync(exec, fs.constants.X_OK);
return true;
} catch(ex) {
}
return typeof(getExecPath(exec)) !== 'undefined';
}