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()); 21 c.end('hello'); 22 }); 23 stdinPipeServer.listen(stdinPipeName); 24 25 const output = []; 26 27 const stdoutPipeServer = net.createServer(function(c) { 28 c.on('data', function(x) { 29 output.push(x); 30 }); 31 c.on('end', common.mustCall(function() { 32 assert.strictEqual(output.join(''), 'hello'); 33 })); 34 }); 35 stdoutPipeServer.listen(stdoutPipeName); 36 37 const args = 38 [`"${__filename}"`, 'child', '<', stdinPipeName, '>', stdoutPipeName]; 39 40 const child = spawn(`"${process.execPath}"`, args, { shell: true }); 41 42 child.on('exit', common.mustCall(function(exitCode) { 43 stdinPipeServer.close(); 44 stdoutPipeServer.close(); 45 assert.strictEqual(exitCode, 0); 46 })); 47} else { 48 // child 49 process.stdin.pipe(process.stdout); 50} 51