Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: complete pipeline with stdio #32373

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/internal/streams/pipeline.js
Expand Up @@ -265,6 +265,13 @@ function pipeline(...streams) {
} else if (isStream(stream)) {
if (isReadable(ret)) {
ret.pipe(stream);

// Compat. Before node v10.12.0 stdio used to throw an error so
// pipe() did/does not end() stdio destinations.
// Now they allow it but "secretly" don't close the underlying fd.
if (stream === process.stdout || stream === process.stderr) {
ret.on('end', () => stream.end());
}
} else {
ret = makeAsyncIterable(ret);

Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-stream-pipeline-process.js
@@ -0,0 +1,29 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const os = require('os');

if (process.argv[2] === 'child') {
const { pipeline } = require('stream');
pipeline(
process.stdin,
process.stdout,
common.mustCall((err) => {
assert.ifError(err);
})
);
} else {
const cp = require('child_process');
cp.exec([
'echo',
'hello',
'|',
`"${process.execPath}"`,
`"${__filename}"`,
'child'
].join(' '), common.mustCall((err, stdout) => {
assert.ifError(err);
assert.strictEqual(stdout.split(os.EOL).shift().trim(), 'hello');
}));
}