#!/usr/bin/node
const { spawn } = require("child_process");
const ls = spawn("./vanitygen", ["-p bc1qu"]);
ls.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
ls.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
ls.on('error', (error) => {
console.log(`error: ${error.message}`);
});
ls.on("close", code => {
console.log(`child process exited with code ${code}`);
});
When I am running it using spawn or exec it finishes immediately and I can't read program output.
child process exited with code 1
Is there any other method to run command and get what it output?
Then detect when its all threads are closed?
If you want to see the program output when it crashes you'll need to let the child process inherit the parent's stdio right from the start, e.g.
Btw, not sure if you meant this too -- if you want your program to pause until the child process complete, use "execSync" instead of "spawn".