I am trying to pipe a child process' standard output to the parent's standard output:
import {exec} from 'child_process';
console.log(new Date() + " starting")
const child = exec(/* some command */);
child.stdout.pipe(process.stdout);
This works, but the child process generates data quite slowly relative to the size of the pipe's buffer. The data comes in large chunks and not frequently.
For example, if I watch the child output stream like this:
child.stdout.on('data', data => console.log(new Date(), data.length));
The output is
2017-11-15T21:53:44.128Z starting
2017-11-15T21:53:58.319Z 8192
2017-11-15T21:54:02.321Z 8192
2017-11-15T21:54:07.384Z 8192
2017-11-15T21:54:11.333Z 8192
2017-11-15T21:54:15.281Z 8192
2017-11-15T21:54:19.008Z 3967
Is there a way to have the child output stream use a smaller buffer or flush more frequently?