11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci// This test is intended for Windows only 41cb0ef41Sopenharmony_ciif (!common.isWindows) 51cb0ef41Sopenharmony_ci common.skip('this test is Windows-specific.'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciif (!process.argv[2]) { 101cb0ef41Sopenharmony_ci // parent 111cb0ef41Sopenharmony_ci const net = require('net'); 121cb0ef41Sopenharmony_ci const spawn = require('child_process').spawn; 131cb0ef41Sopenharmony_ci const path = require('path'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci const pipeNamePrefix = `${path.basename(__filename)}.${process.pid}`; 161cb0ef41Sopenharmony_ci const stdinPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdin`; 171cb0ef41Sopenharmony_ci const stdoutPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdout`; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci const stdinPipeServer = net.createServer(function(c) { 201cb0ef41Sopenharmony_ci c.on('end', common.mustCall()); 211cb0ef41Sopenharmony_ci c.end('hello'); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci stdinPipeServer.listen(stdinPipeName); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci const output = []; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const stdoutPipeServer = net.createServer(function(c) { 281cb0ef41Sopenharmony_ci c.on('data', function(x) { 291cb0ef41Sopenharmony_ci output.push(x); 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci c.on('end', common.mustCall(function() { 321cb0ef41Sopenharmony_ci assert.strictEqual(output.join(''), 'hello'); 331cb0ef41Sopenharmony_ci })); 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci stdoutPipeServer.listen(stdoutPipeName); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci const args = 381cb0ef41Sopenharmony_ci [`"${__filename}"`, 'child', '<', stdinPipeName, '>', stdoutPipeName]; 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci const child = spawn(`"${process.execPath}"`, args, { shell: true }); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci child.on('exit', common.mustCall(function(exitCode) { 431cb0ef41Sopenharmony_ci stdinPipeServer.close(); 441cb0ef41Sopenharmony_ci stdoutPipeServer.close(); 451cb0ef41Sopenharmony_ci assert.strictEqual(exitCode, 0); 461cb0ef41Sopenharmony_ci })); 471cb0ef41Sopenharmony_ci} else { 481cb0ef41Sopenharmony_ci // child 491cb0ef41Sopenharmony_ci process.stdin.pipe(process.stdout); 501cb0ef41Sopenharmony_ci} 51