Reputation: 3
prompt.js:
var inquirer = require("inquirer");
console.log("Hi, welcome to Node Pizza");
var questions = [{
type: "confirm",
name: "toBeDelivered",
message: "Is it for a delivery",
default: false
}];
inquirer.prompt( questions, function( answers ) {
console.log("\nOrder receipt:");
console.log( JSON.stringify(answers, null, " ") );
});
index.js:
var childProcess = require('child_process');
var cp = childProcess.exec('node prompt.js', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
if (err) {
console.log('exec error: ' + error);
}
});
process.stdin.pipe(cp.stdin);
execute the command in windows7 x64 git shell (node v0.10.26):
node index.js
what you can see is that the shell output nothing and waiting to read input.
why the output like "Hi, welcome to Node Pizza" not output before reading input?
Upvotes: 0
Views: 177
Reputation: 106696
You should use child_process.spawn() instead of child_process.exec() since exec() buffers output and waits until the process exits.
Upvotes: 1