From 68edb7c480629fecf33e02fed6f7ee4fe610d38d Mon Sep 17 00:00:00 2001 From: ChangHwan Kim Date: Thu, 18 Apr 2024 13:49:08 +0900 Subject: [PATCH] remove default trim on result of exec command and add noTrim option --- src/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1dfbce7..f930e32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -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, }) }) })