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') })