Skip to content

Commit

Permalink
remove default trim on result of exec command and add noTrim option
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbob13 committed Apr 18, 2024
1 parent 6c57d8f commit 68edb7c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface SSHExecCommandOptions {
stdin?: string | stream.Readable
execOptions?: ExecOptions
encoding?: BufferEncoding
noTrim?: boolean
onChannel?: (clientChannel: ClientChannel) => void
onStdout?: (chunk: Buffer) => void
onStderr?: (chunk: Buffer) => void
Expand Down Expand Up @@ -417,11 +418,18 @@ export class NodeSSH {
signal = signal_ ?? null
})
channel.on('close', () => {
let stdout = output.stdout.join('')
let stderr = output.stderr.join('')
if (options.noTrim === false) {
stdout = stdout.trim()
stderr = stderr.trim()
}

resolve({
code: code != null ? code : null,
signal: signal != null ? signal : null,
stdout: output.stdout.join('').trim(),
stderr: output.stderr.join('').trim(),
stdout: stdout,
stderr: stderr,
})
})
})
Expand Down

0 comments on commit 68edb7c

Please sign in to comment.