mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1020 B
41 lines
1020 B
12 years ago
|
var assert = require('assert');
|
||
|
var cp = require('child_process');
|
||
|
var fs = require('fs');
|
||
|
var path = require('path');
|
||
|
var common = require('../common');
|
||
|
var msg = {test: 'this'};
|
||
|
var nodePath = process.execPath;
|
||
12 years ago
|
var copyPath = path.join(common.tmpDir, 'node-copy.exe');
|
||
12 years ago
|
|
||
|
if (process.env.FORK) {
|
||
|
assert(process.send);
|
||
12 years ago
|
assert.equal(process.argv[0], copyPath);
|
||
12 years ago
|
process.send(msg);
|
||
|
process.exit();
|
||
|
}
|
||
|
else {
|
||
|
try {
|
||
12 years ago
|
fs.unlinkSync(copyPath);
|
||
12 years ago
|
}
|
||
|
catch (e) {
|
||
|
if (e.code !== 'ENOENT') throw e;
|
||
|
}
|
||
12 years ago
|
fs.writeFileSync(copyPath, fs.readFileSync(nodePath));
|
||
|
fs.chmodSync(copyPath, '0755');
|
||
12 years ago
|
|
||
12 years ago
|
// slow but simple
|
||
|
var envCopy = JSON.parse(JSON.stringify(process.env));
|
||
|
envCopy.FORK = 'true';
|
||
12 years ago
|
var child = require('child_process').fork(__filename, {
|
||
12 years ago
|
execPath: copyPath,
|
||
12 years ago
|
env: envCopy
|
||
12 years ago
|
});
|
||
|
child.on('message', common.mustCall(function(recv) {
|
||
|
assert.deepEqual(msg, recv);
|
||
|
}));
|
||
|
child.on('exit', common.mustCall(function(code) {
|
||
12 years ago
|
fs.unlinkSync(copyPath);
|
||
12 years ago
|
assert.equal(code, 0);
|
||
|
}));
|
||
|
}
|