SCP送信をテストするためのコードを書きました。これがコードです。
var async = require('async'),
nexpect = require('nexpect'),
arg = {
'host' : '192.168.0.3',
'username' : 'root',
'password' : 'rootpwd',
'path' : '~'
},
file_list = ['a.txt', 'b.txt', 'c.txt'];
function scpFileTransfer(arg, callback) {
nexpect.spawn('scp ' + arg.file + ' ' + arg.username + '@' + arg.host + ':' + arg.path, { stream: 'stderr' })
.wait(/password/)
.sendline(arg.password)
.run(function (err) {
if(err) console.log(err);
else console.log('from ' + arg.file + ' to ' + arg.username + '@' + arg.host + ':' + arg.path + ' success!');
callback();
}
);
}
async.eachSeries(file_list, function(item, callback) {
arg.file = item;
scpFileTransfer(arg, function () {
callback();
});
}, function (err) {
if(err) console.trace(err);
else console.log('success');
});
このような出力を期待していましたが、
from a.txt to root@192.168.0.3:~ success!
from b.txt to root@192.168.0.3:~ success!
from c.txt to root@192.168.0.3:~ success!
しかし、出力は私の期待とは異なりました。node.js モジュールがコマンド ライン入力を待機していました。コマンド ライン入力なしでコードを実行するにはどうすればよいですか?