1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const child_process = require('child_process'); 5const fixtures = require('../common/fixtures'); 6const { getSystemErrorName } = require('util'); 7 8const testScript = fixtures.path('catch-stdout-error.js'); 9 10const cmd = `${JSON.stringify(process.execPath)} ` + 11 `${JSON.stringify(testScript)} | ` + 12 `${JSON.stringify(process.execPath)} ` + 13 '-pe "process.stdin.on(\'data\' , () => process.exit(1))"'; 14 15const child = child_process.exec(cmd); 16let output = ''; 17 18child.stderr.on('data', function(c) { 19 output += c; 20}); 21 22 23child.on('close', common.mustCall(function(code) { 24 try { 25 output = JSON.parse(output); 26 } catch { 27 console.error(output); 28 process.exit(1); 29 } 30 31 assert.strictEqual(output.code, 'EPIPE'); 32 assert.strictEqual(getSystemErrorName(output.errno), 'EPIPE'); 33 assert.strictEqual(output.syscall, 'write'); 34 console.log('ok'); 35})); 36