2011-07-30 00:22:21 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var Process = process.binding('process_wrap').Process;
|
|
|
|
var Pipe = process.binding('pipe_wrap').Pipe;
|
|
|
|
var pipe = new Pipe();
|
|
|
|
var p = new Process();
|
|
|
|
|
|
|
|
var processExited = false;
|
|
|
|
var gotPipeEOF = false;
|
|
|
|
var gotPipeData = false;
|
|
|
|
|
2011-08-01 00:58:10 +02:00
|
|
|
p.onexit = function(exitCode, signal) {
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('exit');
|
2011-07-30 00:22:21 +02:00
|
|
|
p.close();
|
|
|
|
pipe.readStart();
|
|
|
|
|
2011-08-01 00:58:10 +02:00
|
|
|
assert.equal(0, exitCode);
|
|
|
|
assert.equal(0, signal);
|
|
|
|
|
2011-07-30 00:22:21 +02:00
|
|
|
processExited = true;
|
2011-10-05 00:08:18 +02:00
|
|
|
};
|
2011-07-30 00:22:21 +02:00
|
|
|
|
2013-07-19 23:33:06 +02:00
|
|
|
pipe.onread = function(err, b, off, len) {
|
2011-07-30 00:22:21 +02:00
|
|
|
assert.ok(processExited);
|
|
|
|
if (b) {
|
|
|
|
gotPipeData = true;
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('read %d', len);
|
2011-07-30 00:22:21 +02:00
|
|
|
} else {
|
|
|
|
gotPipeEOF = true;
|
|
|
|
pipe.close();
|
|
|
|
}
|
2011-10-05 00:08:18 +02:00
|
|
|
};
|
2011-07-30 00:22:21 +02:00
|
|
|
|
|
|
|
p.spawn({
|
|
|
|
file: process.execPath,
|
2011-10-05 00:08:18 +02:00
|
|
|
args: [process.execPath, '-v'],
|
2012-05-16 18:04:24 +02:00
|
|
|
stdio: [
|
|
|
|
{ type: 'ignore' },
|
|
|
|
{ type: 'pipe', handle: pipe },
|
|
|
|
{ type: 'ignore' }
|
|
|
|
]
|
2011-07-30 00:22:21 +02:00
|
|
|
});
|
|
|
|
|
2014-03-06 21:44:18 +01:00
|
|
|
// 'this' safety
|
|
|
|
// https://github.com/joyent/node/issues/6690
|
|
|
|
assert.throws(function() {
|
|
|
|
var notp = { spawn: p.spawn };
|
|
|
|
notp.spawn({
|
|
|
|
file: process.execPath,
|
|
|
|
args: [process.execPath, '-v'],
|
|
|
|
stdio: [
|
|
|
|
{ type: 'ignore' },
|
|
|
|
{ type: 'pipe', handle: pipe },
|
|
|
|
{ type: 'ignore' }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}, TypeError);
|
2011-07-30 00:22:21 +02:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.ok(processExited);
|
|
|
|
assert.ok(gotPipeEOF);
|
|
|
|
assert.ok(gotPipeData);
|
|
|
|
});
|