How would I respond to a command line prompt programmatically with node.js? For example, if I do process.stdin.write('sudo ls');
The command line will prompt for a password. Is there an event for 'prompt?'
Also, how do I know when something like process.stdin.write('npm install')
is complete?
I'd like to use this to make file edits (needed to stage my app), deploy to my server, and reverse those file edits (needed for eventually deploying to production).
Any help would rock!
You'll want to use
child_process.exec()
to do this rather than writing the command tostdin
.For the
npm install
one you might be better off withchild_process.spawn()
which will let you attach an event listener to run when the process exits. You could do the following: