From 885f72b93a24e2c07741fa46265091f274b22b10 Mon Sep 17 00:00:00 2001 From: Mohamed Akram Date: Sat, 24 Jan 2026 02:41:20 +0400 Subject: [PATCH] process: do not truncate long strings in `--print` Fixes: https://github.com/nodejs/node/issues/61337 --- lib/internal/process/execution.js | 8 ++++++-- test/parallel/test-cli-eval.js | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index f2407949c2a1b6..9f484e6a611d33 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -455,8 +455,12 @@ function runScriptInContext(name, body, breakFirstLine, print, module, baseUrl, if (print) { const { log } = require('internal/console/global'); - process.on('exit', () => { - log(result); + const printResult = () => log(result); + + process.on('exit', printResult); + process.once('beforeExit', () => { + printResult(); + process.off('exit', printResult); }); } if (origModule !== undefined) diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index 9ec0fece409068..8d765f10fbcbdb 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -115,6 +115,12 @@ child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "\\-42"`, common. assert.strictEqual(stderr, ''); })); +// Long output should not be truncated. +child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "'1'.repeat(1e5)"`, common.mustSucceed((stdout, stderr) => { + assert.strictEqual(stdout, `${'1'.repeat(1e5)}\n`); + assert.strictEqual(stderr, ''); +})); + child.exec(...common.escapePOSIXShell`"${process.execPath}" --use-strict -p process.execArgv`, common.mustSucceed((stdout, stderr) => { assert.strictEqual(