2024-08-15 12:38:46 -04:00
|
|
|
import child_process from "node:child_process";
|
|
|
|
import console from "node:console";
|
|
|
|
|
|
|
|
const child = child_process.spawn("./test-pipe/target/debug/test-pipe", [], {
|
|
|
|
stdio: ["inherit", "inherit", "inherit", "ignore", "pipe"],
|
|
|
|
});
|
|
|
|
|
|
|
|
const extra = child.stdio[4];
|
|
|
|
|
2024-10-24 00:13:30 -04:00
|
|
|
if (!extra) {
|
|
|
|
throw new Error("no extra pipe");
|
|
|
|
}
|
|
|
|
|
|
|
|
const p = Promise.withResolvers<void>();
|
|
|
|
|
|
|
|
let got = "";
|
2024-08-15 12:38:46 -04:00
|
|
|
|
|
|
|
child.on("close", () => {
|
|
|
|
console.log("child closed");
|
2024-10-24 00:13:30 -04:00
|
|
|
console.log("got:", got);
|
|
|
|
if (got === "hello world") {
|
|
|
|
p.resolve();
|
|
|
|
} else {
|
|
|
|
p.reject(new Error(`wanted "hello world", got "${got}"`));
|
|
|
|
}
|
2024-08-15 12:38:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
extra.on("data", (d) => {
|
2024-10-24 00:13:30 -04:00
|
|
|
got += d.toString();
|
2024-08-15 12:38:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
extra.on("close", () => {
|
|
|
|
console.log("pipe closed");
|
|
|
|
});
|
|
|
|
|
2024-10-24 00:13:30 -04:00
|
|
|
extra.write("start");
|
|
|
|
|
2024-08-15 12:38:46 -04:00
|
|
|
await p.promise;
|