2
nodeという名前の.jsファイルからコマンド(aws configure)を実行しようとしています。私はchild_processを使っていて、コマンドやバッチファイルを実行できます。しかし、通常、そのファイルがユーザにユーザ名とパスワードのようなものを入力するよう促す場合、私はその対話を行うことができません。ユーザにプロンプトを出すノードの実行コマンド
おそらくノードをユーザの入力の中間者として使用するためにprocess.stdinをノードで使用しようとしましたが、2つをリンクすることはできません。
誰かが素晴らしいアイデアをお持ちの場合は、
var spawn = require('child_process').spawn;
var mystdin = process.stdin;
var conf = spawn('aws configure', {input: mystdin, shell: true});
//When command returns
conf.stdout.on('data', function(data) {
console.log('stdout: ' + data);
//prompt for input
mystdin.resume();
mystdin.setEncoding('utf8');
var util = require('util');
mystdin.on('data', function (text) {
//INSERT ANSWER HERE
console.log('received data:', util.inspect(text));
if (text === 'quit\n') {
done();
}
});
function done() {
console.log('Now that process.stdin is paused, there is nothing more to do.');
process.exit();
}
});
conf.stderr.on('data', function(data) {
console.log('stdout: ' + data);
});
conf.on('close', function(code) {
console.log('child precess exited with code ' + code);
});
これは現在私が現在行っていたパスです。誰かがより良い提案を持っている場合は私に教えてください!
ありがとうございました