【发布时间】:2021-08-31 15:44:29
【问题描述】:
我需要获取 cat 值 txt 返回并将其传递给另一个函数,但当前在 try catch 和 Promise 挂起时出现错误,我该怎么做?
var SSH2Shell = require("ssh2shell");
async function sshFunction() {
let finalList = [];
try {
var host = {
server: {
host: "xxxxxxxxxxxx",
userName: "xxxxxxxxxx",
password: "xxxxxxx",
},
commands: [
"sudo /usr/bin/rootsh -i -u root",
"cd ..; cd u01/scripts/; cat saida.txt",
],
};
finalList.push(
(result = await SSH2Shell(host)),
(callback = function (sessionText) {
let list = [];
list.push(sessionText);
return list; // Return this call back
})
);
} catch {
console.log("error");
}
let resultList = await Promise.all(finalList);
return resultList;
}
var test = sshFunction();
console.log(test);
结果:
error
Promise { <pending> }
【问题讨论】:
-
"...但目前有一个错误" 请edit你的问题显示你得到的确切错误。
标签: node.js asynchronous ssh promise