stderr always coming in stdout

Đang mở
#339 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

  • #342 của @steelbrain — đã đóng, không merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
node.js, typescript
Lĩnh vực
networking

Hướng nghiên cứu

Bắt đầu tại điểm vào ssh.exec với các tùy chọn pty, stdin và stream: 'both' được báo cáo, sau đó theo dõi cách đầu ra của lệnh được gán vào result.stdout và result.stderr. Tái hiện trường hợp sudo apt updat và xác nhận rằng văn bản lỗi được tách vào result.stderr trong khi mã thoát vẫn là 100.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
TypeScript
Star
1k
Fork
94
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của steelbrain/node-ssh

Tất cả issue của steelbrain/node-ssh

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.