[Solved] Can't run Processes at /usr/bin/env: Not a directory

I have a function that runs a Process. Callers pass an executable name in the args:

export function processPromise(options): Promise<string> {
  return new Promise((resolve, reject) => {
    var process = new Process("/usr/bin/env", options);
    process.onStdout((line) => {
      console.log("process output: " + line);
      resolve(line);
    });

    process.onStderr((line) => {
      reject(line);
    });

    process.start();
  });
}

For instance, one caller calls

const options = {
  args: ["git", "remote"],
  cwd: repoDirectory,
};

const stdout = await processPromise(options);

When running this code, I get the error Error launching process: /usr/bin/env, The operation couldn’t be completed. Not a directory. When I open a local terminal in Nova and run /usr/bin/env git, it runs git successfully.

What’s happening here? Do extensions run in some kind of quarantine? What’s the best way to run git here?

Hm, this reproduces even with other executables. For example, I changed the function above to be git-specific and to read the value of the executable from a setting. I set the value of the setting to /usr/local/bin/git, which my local value for which git. I get the output Error launching process: /usr/local/bin/git, The operation couldn’t be completed. Not a directory

New function:

function gitPromise(options: TaskProcessAction): Promise<string> {
  return new Promise((resolve, reject) => {
    const gitExecutable = nova.workspace.config.get(
      "com.harrytwyford.sourcegraph.config.gitExecutable",
      "string"
    );
    if (!gitExecutable) {
      reject("Please specify a git executable in settings.");
      return;
    }
    const process = new Process(gitExecutable, options);
    process.onStdout((line) => {
      console.log("process output: " + line);
      resolve(line);
    });

    process.onStderr((line) => {
      reject(line);
    });

    process.start();
  });
}

I tried running the extension on a different computer and got the same error. The githelpers branch on the extension’s repo contains the affected code.

Ah, the issue was that my value for repoDirectory was wrong, so options.cwd pointed to a file. Hence “Not a directory”. Whoops!