Skip to content

Commit c7dc638

Browse files
committed
process: fix output truncated
Fixes: #61337
1 parent 01ff6ce commit c7dc638

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/internal/process/execution.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,17 @@ function runScriptInContext(name, body, breakFirstLine, print, module, baseUrl,
454454
});
455455
if (print) {
456456
const { log } = require('internal/console/global');
457+
let printed = false;
457458

458-
process.on('exit', () => {
459+
process.once('beforeExit', () => {
460+
printed = true;
459461
log(result);
460462
});
463+
464+
process.once('exit', () => {
465+
if (!printed)
466+
log(result);
467+
});
461468
}
462469
if (origModule !== undefined)
463470
globalThis.module = origModule;

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)