Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ended up doing the following:</p> <pre><code> //create a new stdout file stream var stdoutFS = fs.createWriteStream(stdoutFile, { encoding: 'utf8', flags : 'a+' }); //create a new stderr file stream var stderrFS = fs.createWriteStream(stderrFile, { encoding: 'utf8', flags : 'a+' }); //pipe stdout to a worker file var unhookStdout = hookWriteStream(stdout, function(string, encoding, fd) { stdoutFS.write(string, encoding || 'utf8'); }); console.log('\n\nPrepared new stdout hook to worker file.'); //pipe stderr to a worker file var unhookStderr = hookWriteStream(stderr, function(string, encoding, fd) { stderrFS.write(string, encoding || 'utf8'); }); console.log('Prepared new stderr hook to worker file.'); //unhook when things go wrong stdoutFS.once('close', function() { unhookStdout(); console.log('Unhooked stdout.'); }); stdoutFS.once('error', function(err) { unhookStdout(); console.error('Error: Unhooked stdout due to error %j.', err); }); stderrFS.once('close', function() { unhookStderr(); console.log('Unhooked stderr.'); }); stderrFS.once('error', function(err) { unhookStderr(); console.error('Error: Unhooked stderr due to error %j.', err); }); }); function hookWriteStream(stream, callback) { var oldWrite = stream.write; stream.write = (function(write) { return function(string, encoding, fd) { write.apply(stream, arguments); callback(string, encoding, fd); }; })(stream.write); return function() { stream.write = oldWrite; }; } </code></pre> <p>It may not be very elegant, but so far this is the best solution I've found.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload