Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1x 4x 4x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x | const { execFile } = require('child_process'); /** * @typedef {Object} Options * @property {'buffer' | null} encoding `encoding` means stdout/stderr are definitely `Buffer`. * * @typedef {import("child_process").ExecOptions} ExecOptions * @param {string} command * @param {ExecOptions & Options} options * @returns {Promise<string>} */ function whereis(command, options) { return new Promise((resolve, reject) => { if (!command) { return reject(new Error('No command name is passed!')); } const commandStr = /(win32)/.test(process.platform) ? `${command}.exe` : command; execFile('which', [commandStr], options, (error, stdout, stderr) => { if (error) { reject(new Error(`Could not find ${command} on your system; ${error.message ? error.message : ''}`)); return; } const str = stdout.toString().split('\n')[0]; Iif (str === '' || str.charAt(0) !== '/') { reject(new Error(`Could not find ${command} on your system;`)); } resolve(str); }); }); } module.exports = whereis; |