NodeJS spawn executable on Mac giving Unknown system error -8

128 views Asked by At

I have an executable that I'm trying to work with in NodeJS on Mac, I'll call it prog. It takes quite afew args that can be very lengthy individually and contains a mix of single and double quotes and spaces, it will produce large amounts of text on it's output while sometimes taking hours to finish. Using the hack noted below, I already know that the entire script works correctly but the hack feels very dirty.

I am trying to directly call prog from within my script, run.js and it gives the following error:

$ ./run.js
node:internal/child_process:421
    throw new ErrnoException(err, 'spawn');
    ^

Error: spawn Unknown system error -8
    at ChildProcess.spawn (node:internal/child_process:421:11)
    at Object.spawn (node:child_process:761:9)
    at Object.<anonymous> (./run.js:2:26)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  errno: -8,
  code: 'Unknown system error -8',
  syscall: 'spawn'
}

Node.js v21.3.0

My directory contains both run.js and prog, as a test I reduced and moved the spawn call to the top of the script and it still gives the same Error so here is the script including the error line.

#! /usr/local/bin/node
require('child_process').spawn(__dirname+'/prog');

Even calling it via './prog' does not work. My Mac version is 12.7.1 and Node.js is 21.3 The only way I've found to make it work is to make an entirely separate file, lets call it "macHack.sh"

#!/bin/bash
./prog "$@"
exit $?

and changing the command in spawn to './macHack.sh' This solution feels very hacky and wasteful, while also requiring shipping another file for my program that has the intended goal of being a single file wrapper around prog that can be easily shared by just the contents of the run file.

I have spent days rummaging through google attempting to solve this completely inside my NodeJS script with no solutions.

0

There are 0 answers