steelbrain / steelbrain/node-ssh
stderr always coming in stdout
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ssh.exec entry point with the reported pty, stdin, and stream: 'both' options, then trace how the command's output is assigned to result.stdout and result.stderr. Reproduce the sudo apt updat case and confirm that the error text is separated into result.stderr while the exit code remains 100.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100