I've found an issue that I've never seen before. I've tried to run a nodejs process through NodeJS's builtin Child_Process
module. I achieved it like this:
const child_process = require('child_process');
const proc = child_process.exec("node test.js");
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
proc.on('exit', code => console.log("Process exited with code", code));
The interesting thing though, that the process exits with a non-zero exit code although the process runs fine in a standard terminal session. In this case I'm using Bash.
The script looks like this:
for (const i of new Array(10).fill(0).map((a, i) => i))
console.log(i ** 2);
It prints the square of the numbers 0 - 10.
I've written the script in Bash and Python and each produce the correct result. The output is printed to process.stdout
.
I can run the JavaScript example in Deno as well, however, the result is the same as in Node.
I've never seen this behaviour before and the docs don't seem to have much of a solution to this. The closest I got was a suggestion stating to access the streams through proc.stdio
, which also produced the same result.