Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/main-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})