Last active
November 24, 2015 21:16
-
-
Save sshilko/fe990f5fa386175b6de4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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