INNER CODE UNIT · JavaScript

commandExists

linxidnju/OpenTag · src/cli.js:223

async function commandExists(command) {
  if (!command) return false;
  if (command.includes("/") || command.includes("\\")) {
    try {
      await access(command, constants.X_OK);
      return true;
    } catch {
      return false;
    }
  }
  return new Promise((resolve) => {
    const child = spawn(process.platform === "win32" ? "where" : "command", process.platform === "win32" ? [command] : ["-v", command], {
      shell: process.platform !== "win32",
      stdio: "ignore"
    });
    child.on("close", (code) => resolve(code === 0));
    child.on("error", () => resolve(false));
  });

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…