node/test/mjsunit/test-process-simple.js

35 lines
725 B
JavaScript
Raw Normal View History

include("common.js");
2009-06-21 19:57:23 +08:00
var cat = node.createChildProcess("cat");
2009-06-21 19:57:23 +08:00
var response = "";
var exit_status = -1;
2009-06-29 19:18:30 +08:00
cat.addListener("output", function (chunk) {
puts("stdout: " + JSON.stringify(chunk));
2009-06-21 20:07:52 +08:00
if (chunk) {
response += chunk;
if (response === "hello world") {
puts("closing cat");
cat.close();
}
2009-06-21 20:07:52 +08:00
}
2009-06-28 02:40:43 +08:00
});
2009-06-29 19:18:30 +08:00
cat.addListener("error", function (chunk) {
puts("stderr: " + JSON.stringify(chunk));
2009-06-21 19:57:23 +08:00
assertEquals(null, chunk);
2009-06-28 02:40:43 +08:00
});
cat.addListener("exit", function (status) {
puts("exit event");
exit_status = status;
});
2009-06-21 19:57:23 +08:00
2009-08-27 00:22:00 +08:00
cat.write("hello");
cat.write(" ");
cat.write("world");
2009-06-21 19:57:23 +08:00
process.addListener("exit", function () {
2009-06-21 19:57:23 +08:00
assertEquals(0, exit_status);
assertEquals("hello world", response);
});