Skip to content

Instantly share code, notes, and snippets.

@mcculloughsean
Created October 17, 2012 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcculloughsean/3908099 to your computer and use it in GitHub Desktop.
Save mcculloughsean/3908099 to your computer and use it in GitHub Desktop.
Pipe stdin to a file
#!/usr/bin/env node
var fs = require('fs');
var outputFile, outputStream;
if (process.argv[1] == __filename)
outputFile = process.argv[2];
if (!outputFile) {
throw "Must specify a filename";
}
outputStream = fs.createWriteStream(outputFile);
process.stdin.pipe(outputStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment