scp 전송을 테스트하기위한 코드를 작성했습니다. 이것은 코드입니다. nexpect 모듈의 Node.js 대기 함수가 작동하지 않습니다.
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 [email protected]:~ success!
from b.txt to [email protected]:~ success!
from c.txt to [email protected]:~ success!
을 예상하지만 출력은 내 기대와 달랐다. 내 node.js 모듈이 명령 행 입력을 대기 중입니다. 명령 줄 입력없이 코드를 어떻게 실행합니까?