Created
July 11, 2014 05:45
-
-
Save shovon/513dd6cbf657301bfb20 to your computer and use it in GitHub Desktop.
An example to synchronously read from the command line.
This file contains 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
var child_process = require('child_process'); | |
var fs = require('fs'); | |
process.stdout.pause(); | |
var fd = child_process.execFile('/bin/sh', ["-c", "read LINE < /dev/tty; echo $LINE > stdout; echo 1 > done"]); | |
while (true) { | |
try { | |
if (fs.readFileSync('done', {encoding: 'utf8'}).trim() === '1') { break; } | |
} catch (e) {} | |
} | |
console.log(fs.readFileSync('stdout', {encoding: 'utf8'}).trim()); | |
fs.unlinkSync('stdout'); | |
fs.unlinkSync('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment