Send User Input From Nodejs To Shell Script
I have this NodeJS script: var util = require('util'), process = require('child_process'), ls = process.exec('test.sh'); ls.stdout.on('data', function (data) { console.log
Solution 1:
You will have to say something like this:
ls.stdin.write('test\n');
OR
you can inherit standard streams if you want input from user using spawn
.
like this:
var spawn = require('child_process').spawn;
spawn('sh',['test.sh'], { stdio: 'inherit' });
Solution 2:
Did you try adding '\n'
to the end of your input (e.g. ls.stdin.write('Test\n');
) to simulate pressing return/enter?
Also, you want process.spawn
, not process.exec
. The latter does not have a streaming interface like you are using, but it instead executes the command and buffers stdout and stderr output (passing it to the callback given to process.exec()
).
Post a Comment for "Send User Input From Nodejs To Shell Script"