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 fs.readFile('/dev/stdin', function(er, data) { 15 assert.ifError(er); 16 process.stdout.write(data); 17 }); 18 return; 19} 20 21const tmpdir = require('../common/tmpdir'); 22 23const filename = path.join(tmpdir.path, '/readfile_pipe_large_test.txt'); 24const dataExpected = 'a'.repeat(999999); 25tmpdir.refresh(); 26fs.writeFileSync(filename, dataExpected); 27 28const exec = require('child_process').exec; 29const f = JSON.stringify(__filename); 30const node = JSON.stringify(process.execPath); 31const cmd = `cat ${filename} | ${node} ${f} child`; 32exec(cmd, { maxBuffer: 1000000 }, common.mustSucceed((stdout, stderr) => { 33 assert.strictEqual( 34 stdout, 35 dataExpected, 36 `expect it reads the file and outputs 999999 'a' but got : ${stdout}` 37 ); 38 assert.strictEqual( 39 stderr, 40 '', 41 `expect that it does not write to stderr, but got : ${stderr}` 42 ); 43 console.log('ok'); 44})); 45