Reputation: 193
I've an issue with Node.js. With Python, if I wanted to execute an external command, I used to do something like this:
import subprocess
subprocess.call("bower init", shell=True)
I've read about child_process.exec
and spawn
in Node.js but I can't do what I want. And what's I want?
I want to execute an external command (like bower init
) and see its output in real time and interact with bower itself. The only thing I can do is receive the final output but that don't allow me to interact with the program.
Regards
Edit: I saw this question but the answer doesn't work here. I want to send input when the external program needs it.
Upvotes: 4
Views: 574
Reputation: 2937
How about this?
var childProcess = require('child_process');
var child = childProcess.spawn('bower', ['init'], {
env: process.env,
stdio: 'inherit'
});
child.on('close', function(code) {
process.exit(code);
});
Seemed to work for me
Upvotes: 3