我正在尝试yum install <package_name>
使用 ssh2-promise 包在远程 linux 服务器上执行命令,但我无法获取命令响应以进行进一步处理和验证。
我尝试了以下方法,
// Node:33528) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
(async function(){
try {
const data = await this.ssh.exec("yum repolist all");
console.log("resp: ", data);
} catch(e) {
console.log(e)
}
})(); // This fails
const socket = await this.ssh.spawn("yum repolist all");
socket.on('data', function(data) {
console.log("resp: " , data); // I get binary data not the human readable output
});
// Node:33528) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
this.ssh.exec("yum install <name>").then((data) => {
console.log("resp: yum repolist all output: ", data); // This also fails and throws exception
});
// Throws again (Node:33528) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
const output = await this.ssh.exec("yum upgrade <name>");
console.log("resp: ", output)
我也尝试了适当的 try catch 块,仍然抛出 unhandledPromise 异常。有人可以帮我解决这个问题吗?