Skip to content

Commit c1402c6

Browse files
authored
process: do not truncate long strings in --print
Fixes: #61337 PR-URL: #61497 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8117cb0 commit c1402c6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/internal/process/execution.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,12 @@ function runScriptInContext(name, body, breakFirstLine, print, module, baseUrl,
455455
if (print) {
456456
const { log } = require('internal/console/global');
457457

458-
process.on('exit', () => {
459-
log(result);
458+
const printResult = () => log(result);
459+
460+
process.on('exit', printResult);
461+
process.once('beforeExit', () => {
462+
printResult();
463+
process.off('exit', printResult);
460464
});
461465
}
462466
if (origModule !== undefined)

test/parallel/test-cli-eval.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "\\-42"`, common.
115115
assert.strictEqual(stderr, '');
116116
}));
117117

118+
// Long output should not be truncated.
119+
child.exec(...common.escapePOSIXShell`"${process.execPath}" -p "'1'.repeat(1e5)"`, common.mustSucceed((stdout, stderr) => {
120+
assert.strictEqual(stdout, `${'1'.repeat(1e5)}\n`);
121+
assert.strictEqual(stderr, '');
122+
}));
123+
118124
child.exec(...common.escapePOSIXShell`"${process.execPath}" --use-strict -p process.execArgv`,
119125
common.mustSucceed((stdout, stderr) => {
120126
assert.strictEqual(

0 commit comments

Comments
 (0)