perf: ssh伪终端模式优化,windows下不开启

This commit is contained in:
xiaojunnuo
2025-04-21 17:34:26 +08:00
parent 8385bcc2d7
commit 42dfe936b7
2 changed files with 13 additions and 13 deletions

View File

@@ -170,9 +170,10 @@ export class AsyncSsh2Client {
// }
return new Promise((resolve, reject) => {
this.logger.info(`执行命令:[${this.connConf.host}][exec]: \n` + script);
// pty 必须为false 否则返回值会带上 所有输出,影响返回结果判断, 比如 root#: xxxx
// 当使用keyboard-interactive 登录时需要pty
this.conn.exec(script, { pty: this.connConf.pty ?? false, env: opts.env }, (err: Error, stream: any) => {
// pty 伪终端window下的输出会带上conhost.exe之类的多余的字符串影响返回结果判断
// linux下 当使用keyboard-interactive 登录时需要pty
const pty = !this.connConf.windows //linux下开启伪终端windows下不开启
this.conn.exec(script, { pty, env: opts.env }, (err: Error, stream: any) => {
if (err) {
reject(err);
return;