stderr always coming in stdout

未关闭
#339 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #342 来自 @steelbrain —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
领域
networking

调研方向

从 ssh.exec 入口点开始,使用报告中的 pty、stdin 和 stream: 'both' 选项,然后跟踪命令输出是如何分配给 result.stdout 和 result.stderr 的。重现 sudo apt updat 的情况,并确认错误文本被分离到 result.stderr 中,同时退出代码仍为 100。

由索引模型根据 Issue 内容生成。

描述

Hi,

I have faced an issue, which always returns stderr in result.stdout rather than result.stderr.
node-ssh version 10.0.2

ssh.connect({
  host: 'localhost',
  username: '<username>',
  password: '<password>'
}).then(() => {
  ssh.exec('sudo apt updat', [], {
    execOptions: { pty : true },
    stdin: '<password>\n',
    stream: 'both'
  }).then((result) => {
    console.log("Result StdOut", result.stdout)
    console.log("Result StdErr", result.stderr)
    console.log("Result", result)
  })
})

Note: Intensively I make an error in the command sudo apt updat to expecting error.

When I execute above code I got the error always in the stdout.

Result StdOut 
[sudo] password for <username>: 
E: Invalid operation updat
Result StdErr 
Result {
  code: 100,
  signal: null,
  stdout: '<password>\r\n' +
    '[sudo] password for <username>: \r\n' +
    '\u001b[1;31mE: \u001b[0mInvalid operation updat\u001b[0m',
  stderr: ''
}

But the same is working expected using ssh2
Below is the sample.

var Client = require('ssh2').Client;
 
var conn = new Client();
conn.on('ready', function() {
  console.log('Client :: ready');
  conn.exec('apt updat', function(err, stream) {
    if (err) throw err;
    stream.on('close', function(code, signal) {
      console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
      conn.end();
    }).on('data', function(data) {
      console.log('STDOUT: ' + data);
    }).stderr.on('data', function(data) {
      console.log('STDERR: ' + data);
    });
  });
}).connect({
  host: 'localhost',
  port: 22,
  username: '<username>',
  password: '<password>'
});

Output is

STDERR: 
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.


STDERR: E: Invalid operation updat
STDERR: 

Stream :: close :: code: 100, signal: undefined
主要语言
TypeScript
星标
1k
派生
94
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

steelbrain/node-ssh 的其他 Issue

查看 steelbrain/node-ssh 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。