1'use strict'; 2const common = require('../common'); 3 4// Simulate `cat readfile.js | node readfile.js` 5 6if (common.isWindows || common.isAIX) 7 common.skip(`No /dev/stdin on ${process.platform}.`); 8 9const assert = require('assert'); 10const path = require('path'); 11const fs = require('fs'); 12 13if (process.argv[2] === 'child') { 14 process.stdout.write(fs.readFileSync('/dev/stdin', 'utf8')); 15 return; 16} 17 18const tmpdir = require('../common/tmpdir'); 19 20const filename = path.join(tmpdir.path, '/readfilesync_pipe_large_test.txt'); 21const dataExpected = 'a'.repeat(999999); 22tmpdir.refresh(); 23fs.writeFileSync(filename, dataExpected); 24 25const exec = require('child_process').exec; 26const f = JSON.stringify(__filename); 27const node = JSON.stringify(process.execPath); 28const cmd = `cat ${filename} | ${node} ${f} child`; 29exec( 30 cmd, 31 { maxBuffer: 1000000 }, 32 common.mustSucceed((stdout, stderr) => { 33 assert.strictEqual(stdout, dataExpected); 34 assert.strictEqual(stderr, ''); 35 console.log('ok'); 36 }) 37); 38