node/test/simple/test-child-process-bufferin...

36 lines
741 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 spawn = require('child_process').spawn;
var pwd_called = false;
function pwd(callback) {
var output = '';
var child = spawn('pwd');
2010-03-18 05:00:17 +08:00
child.stdout.setEncoding('utf8');
child.stdout.addListener('data', function(s) {
console.log('stdout: ' + JSON.stringify(s));
2010-03-18 05:00:17 +08:00
output += s;
2009-06-28 02:40:43 +08:00
});
2010-03-18 05:00:17 +08:00
child.addListener('exit', function(c) {
console.log('exit: ' + c);
assert.equal(0, c);
callback(output);
pwd_called = true;
2009-06-28 02:40:43 +08:00
});
}
pwd(function(result) {
2010-10-12 07:09:02 +08:00
console.dir(result);
assert.equal(true, result.length > 1);
assert.equal('\n', result[result.length - 1]);
2009-08-27 00:22:00 +08:00
});
process.addListener('exit', function() {
assert.equal(true, pwd_called);
});