node/test/simple/test-child-process-stdout-f...

29 lines
660 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-03-18 05:00:17 +08:00
var path = require('path');
var spawn = require('child_process').spawn;
var sub = path.join(common.fixturesDir, 'print-chars.js');
2010-03-18 05:00:17 +08:00
2010-12-05 07:20:34 +08:00
var n = 500000;
2010-03-18 05:00:17 +08:00
var child = spawn(process.argv[0], [sub, n]);
var count = 0;
child.stderr.setEncoding('utf8');
child.stderr.addListener('data', function(data) {
console.log('parent stderr: ' + data);
2010-03-18 05:00:17 +08:00
assert.ok(false);
});
child.stderr.setEncoding('utf8');
child.stdout.addListener('data', function(data) {
2010-03-18 05:00:17 +08:00
count += data.length;
console.log(count);
2010-03-18 05:00:17 +08:00
});
child.addListener('exit', function(data) {
2010-03-18 05:00:17 +08:00
assert.equal(n, count);
console.log('okay');
2010-03-18 05:00:17 +08:00
});