Skip to content

Instantly share code, notes, and snippets.

@sshilko
Last active November 24, 2015 21:16
Show Gist options
  • Select an option

  • Save sshilko/fe990f5fa386175b6de4 to your computer and use it in GitHub Desktop.

Select an option

Save sshilko/fe990f5fa386175b6de4 to your computer and use it in GitHub Desktop.
/**
* Read input, line-by-line until get enough lines
*/
var input = [];
var wantlines = 2;
process.stdin.setEncoding('utf8');
var readline = require('readline');
var rl = readline.createInterface({ input: process.stdin });
rl.on('line', function (cmd) {
if (input.length <= wantlines-1 && String(cmd).length > 0) {
input.push(cmd.trim());
if (input.length == wantlines) {
/**
* got needed input, do something
*/
result = 'do something with input';
process.stdout.write(result);
process.exit();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment