I'm getting an error on windows 10 when I try to run spawn
var spawn = require('child_process').spawn;
var child = spawn(path.join(__dirname, '../bin/run.js'), {}, {env: env});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
Here is the error message. I couldn't find much about resolving this issue.
[14:58:15] Error: spawn UNKNOWN
I installed node with nvs
which appears to be working fine for everything else.
So I figured out its the run.js
which is a node script with a shebang, but that doesn't work on windows.
I tried changing it to spawn('node run.js')
but now I get NOENT.
The spawn function launches a command in a new process and we can use it to pass that command any arguments. For example, here's code to spawn a new process that will execute the pwd command. const { spawn } = require('child_process'); const child = spawn('pwd');
spawn() : The spawn function launches a command in a new process and you can use it to pass that command any arguments. It's the most generic spawning function and all other functions are built over it [docs]. child_process. execFile() : The execFile function is similar to child_process.
I had to pass an array of args to node
. On windows shebang lines don't work so the command I'm executing is actually node
and the path to the run.js
is an argument.
spawn('node', ['run.js'])
works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With