mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
f8a3cf980f
The child process 'exit' was returning the status of the process, rather than the exit code. This patch properly deconstructs the status into the exit code and the term signal a process may have received. See: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Watcher_Specific_Functions_and_Data_-5 and waitpid(2)
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
require("../common");
|
|
var exec = require('child_process').exec;
|
|
success_count = 0;
|
|
error_count = 0;
|
|
|
|
exec("ls /", function (err, stdout, stderr) {
|
|
if (err) {
|
|
error_count++;
|
|
puts("error!: " + err.code);
|
|
puts("stdout: " + JSON.stringify(stdout));
|
|
puts("stderr: " + JSON.stringify(stderr));
|
|
assert.equal(false, err.killed);
|
|
} else {
|
|
success_count++;
|
|
p(stdout);
|
|
}
|
|
});
|
|
|
|
|
|
exec("ls /DOES_NOT_EXIST", function (err, stdout, stderr) {
|
|
if (err) {
|
|
error_count++;
|
|
assert.equal("", stdout);
|
|
assert.equal(true, err.code != 0);
|
|
assert.equal(false, err.killed);
|
|
assert.strictEqual(null, err.signal);
|
|
puts("error code: " + err.code);
|
|
puts("stdout: " + JSON.stringify(stdout));
|
|
puts("stderr: " + JSON.stringify(stderr));
|
|
} else {
|
|
success_count++;
|
|
p(stdout);
|
|
assert.equal(true, stdout != "");
|
|
}
|
|
});
|
|
|
|
exec("sleep 10", { timeout: 50 }, function (err, stdout, stderr) {
|
|
assert.ok(err);
|
|
assert.ok(err.killed);
|
|
assert.equal(err.signal, 'SIGKILL');
|
|
});
|
|
|
|
exec('python -c "print 200000*\'C\'"', { maxBuffer: 1000 }, function (err, stdout, stderr) {
|
|
assert.ok(err);
|
|
assert.ok(err.killed);
|
|
assert.equal(err.signal, 'SIGKILL');
|
|
});
|
|
|
|
process.addListener("exit", function () {
|
|
assert.equal(1, success_count);
|
|
assert.equal(1, error_count);
|
|
});
|