Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Stdout/stderr for writing between procs can be faulty if extra stdio is included

Here is some node.js code:

#!/usr/bin/env node

const fs = require('fs');

const header = '#!/usr/bin/env bash\n\n';
try {
  const bytes = fs.writeSync(3, header, 0);
} catch (err) {
  console.error('Please open file descriptor 3 at the command line.');
  console.error('For example:');
  console.error('bunion --bash-completion 3>');

const w = fs.createWriteStream(null, {fd: 3, encoding: 'utf8', start: header.length});

you can invoke it like so:

 node test/fd-3.js 3>

and then in you will have:

#!/usr/bin/env bash


this way processes can communicate via stdio on fd3, and you can write to stdout/stderr without worring so damn much about altering the important output. Or use JSON to communicate. In other words, stdout becomes for meta-data (instead of all these unimaginative assh*les using stderr for metadata), and fd3 is used for the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.