1'use strict'; 2const common = require('../common'); 3if (!common.isMainThread) 4 common.skip("Workers don't have process-like stdio"); 5 6// Test if Node handles redirecting one child process stdout to another 7// process stdin without crashing. 8const spawn = require('child_process').spawn; 9 10const writeSize = 100; 11const totalDots = 10000; 12 13const who = process.argv.length <= 2 ? 'parent' : process.argv[2]; 14 15switch (who) { 16 case 'parent': { 17 const consumer = spawn(process.argv0, [process.argv[1], 'consumer'], { 18 stdio: ['pipe', 'ignore', 'inherit'], 19 }); 20 const producer = spawn(process.argv0, [process.argv[1], 'producer'], { 21 stdio: ['pipe', consumer.stdin, 'inherit'], 22 }); 23 process.stdin.on('data', () => {}); 24 producer.on('exit', process.exit); 25 break; 26 } 27 case 'producer': { 28 const buffer = Buffer.alloc(writeSize, '.'); 29 let written = 0; 30 const write = () => { 31 if (written < totalDots) { 32 written += writeSize; 33 process.stdout.write(buffer, write); 34 } 35 }; 36 write(); 37 break; 38 } 39 case 'consumer': 40 process.stdin.on('data', () => {}); 41 break; 42} 43