const spawn = require('child_process').spawn const exec = require('child_process').exec const fork = require('child_process').fork const miner = spawn("./miner.sh") const shouldRestart = (line) => { const launchFailString = new RegExp(/unspecified launch failure/) const staleDataString = new RegExp(/Submitting stale solution/) return launchFailString.test(line) || staleDataString.test(line) } miner.stdout.on('data', (data) => { if (shouldRestart(data)) { // exec('reboot') or fork("./stdoutScanner.js") } }) miner.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); miner.on('close', (code) => { console.log(`Miner exited with code: ${code}`) })