1'use strict'; 2const common = require('../common'); 3// This test is intended for Windows only 4if (!common.isWindows) 5 common.skip('this test is Windows-specific.'); 6 7const assert = require('assert'); 8 9if (!process.argv[2]) { 10 // parent 11 const net = require('net'); 12 const spawn = require('child_process').spawn; 13 const path = require('path'); 14 15 const pipeNamePrefix = `${path.basename(__filename)}.${process.pid}`; 16 const stdinPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdin`; 17 const stdoutPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdout`; 18 19 const stdinPipeServer = net.createServer(function(c) { 20 c.on('end', common.mustCall(function() { 21 })); 22 c.end('hello'); 23 }); 24 stdinPipeServer.listen(stdinPipeName); 25 26 const output = []; 27 28 const stdoutPipeServer = net.createServer(function(c) { 29 c.on('data', function(x) { 30 output.push(x); 31 }); 32 c.on('end', common.mustCall(function() { 33 assert.strictEqual(output.join(''), 'hello'); 34 })); 35 }); 36 stdoutPipeServer.listen(stdoutPipeName); 37 38 const args = 39 [`"${__filename}"`, 'child', '<', stdinPipeName, '>', stdoutPipeName]; 40 41 const child = spawn(`"${process.execPath}"`, args, { shell: true }); 42 43 child.on('exit', common.mustCall(function(exitCode) { 44 stdinPipeServer.close(); 45 stdoutPipeServer.close(); 46 assert.strictEqual(exitCode, 0); 47 })); 48} else { 49 // child 50 process.stdin.pipe(process.stdout); 51} 52