2009-06-21 19:57:23 +08:00
|
|
|
include("mjsunit.js");
|
|
|
|
|
|
|
|
var cat = new node.Process("cat");
|
|
|
|
|
|
|
|
var response = "";
|
|
|
|
var exit_status = -1;
|
|
|
|
|
2009-06-28 02:40:43 +08:00
|
|
|
cat.addListener("Output", function (chunk) {
|
2009-06-21 20:07:52 +08:00
|
|
|
if (chunk) {
|
|
|
|
response += chunk;
|
|
|
|
if (response === "hello world") cat.close();
|
|
|
|
}
|
2009-06-28 02:40:43 +08:00
|
|
|
});
|
|
|
|
cat.addListener("Error", function (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) { exit_status = status; });
|
2009-06-21 19:57:23 +08:00
|
|
|
|
|
|
|
function onLoad () {
|
|
|
|
cat.write("hello");
|
|
|
|
cat.write(" ");
|
|
|
|
cat.write("world");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onExit () {
|
|
|
|
assertEquals(0, exit_status);
|
|
|
|
assertEquals("hello world", response);
|
|
|
|
}
|