From e9db2db6fb08cd8f42021a23e093d9e597dc6537 Mon Sep 17 00:00:00 2001 From: Yurii Bakurov <45154988+Yurii201811@users.noreply.github.com> Date: Wed, 17 Jun 2026 00:32:12 +0200 Subject: [PATCH] Document execCommand noTrim output preservation --- README.md | 5 +++++ test/main-test.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index d71a1b9..57d1918 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,11 @@ ssh.connect({ console.log('STDOUT: ' + result.stdout) console.log('STDERR: ' + result.stderr) }) + // Command output is trimmed by default. Pass noTrim when leading or trailing + // whitespace is meaningful, such as reading exact file contents. + ssh.execCommand('git show --textconv HEAD:README.md', { noTrim: true }).then(function(result) { + console.log('STDOUT: ' + result.stdout) + }) // Command with escaped params ssh.exec('hh_client', ['--json'], { cwd: '/var/www', stream: 'stdout', options: { pty: true } }).then(function(result) { console.log('STDOUT: ' + result) diff --git a/test/main-test.ts b/test/main-test.ts index 34adc55..f54b2d8 100644 --- a/test/main-test.ts +++ b/test/main-test.ts @@ -501,4 +501,11 @@ sshit('has a working noTrim option', async function (t, port, client) { const resultWithoutTrim = await client.exec('echo', ['\n\n\nhi\n\n\n'], {stream: 'stdout', noTrim: true}) t.is(resultWithoutTrim, '\n\n\nhi\n\n\n\n') + + const commandResult = await client.execCommand( + 'node -e "process.stdout.write(\'\\nstdout\\n\\n\'); process.stderr.write(\'\\nstderr\\n\\n\')"', + { noTrim: true }, + ) + t.is(commandResult.stdout, '\nstdout\n\n') + t.is(commandResult.stderr, '\nstderr\n\n') })