Skip to content

Commit fa08d1d

Browse files
orangemochaFishrock123
authored andcommitted
test: add test-spawn-cmd-named-pipe
Adding a Windows test to verify that a node process spawned via cmd with named pipes can access its stdio streams. Ref: nodejs/node-v0.x-archive#7345 PR-URL: #2770 Reviewed-By: cjihrig - Colin Ihrig <[email protected]> Reviewed-By: thefourtheye - Sakthipriyan Vairamani <[email protected]> Reviewed-By: evanlucas - Evan Lucas <[email protected]>
1 parent d4cd5ac commit fa08d1d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
// This test is intended for Windows only
6+
if (!common.isWindows) {
7+
console.log('1..0 # Skipped: this test is Windows-specific.');
8+
return;
9+
}
10+
11+
if (!process.argv[2]) {
12+
// parent
13+
const net = require('net');
14+
const spawn = require('child_process').spawn;
15+
const path = require('path');
16+
17+
const pipeNamePrefix = path.basename(__filename) + '.' + process.pid;
18+
const stdinPipeName = '\\\\.\\pipe\\' + pipeNamePrefix + '.stdin';
19+
const stdoutPipeName = '\\\\.\\pipe\\' + pipeNamePrefix + '.stdout';
20+
21+
const stdinPipeServer = net.createServer(function(c) {
22+
c.on('end', common.mustCall(function() {
23+
}));
24+
c.end('hello');
25+
});
26+
stdinPipeServer.listen(stdinPipeName);
27+
28+
const output = [];
29+
30+
const stdoutPipeServer = net.createServer(function(c) {
31+
c.on('data', function(x) {
32+
output.push(x);
33+
});
34+
c.on('end', common.mustCall(function() {
35+
assert.strictEqual(output.join(''), 'hello');
36+
}));
37+
});
38+
stdoutPipeServer.listen(stdoutPipeName);
39+
40+
const comspec = process.env['comspec'];
41+
if (!comspec || comspec.length === 0) {
42+
assert.fail('Failed to get COMSPEC');
43+
}
44+
45+
const args = ['/c', process.execPath, __filename, 'child',
46+
'<', stdinPipeName, '>', stdoutPipeName];
47+
48+
const child = spawn(comspec, args);
49+
50+
child.on('exit', common.mustCall(function(exitCode) {
51+
stdinPipeServer.close();
52+
stdoutPipeServer.close();
53+
assert.strictEqual(exitCode, 0);
54+
}));
55+
} else {
56+
// child
57+
process.stdin.pipe(process.stdout);
58+
}

0 commit comments

Comments
 (0)