blob: 2837cdc53cc01b9768d4a1a04ea73d0d7dceaa0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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];
if (!extra) {
throw new Error("no extra pipe");
}
const p = Promise.withResolvers<void>();
let got = "";
child.on("close", () => {
console.log("child closed");
console.log("got:", got);
if (got === "hello world") {
p.resolve();
} else {
p.reject(new Error(`wanted "hello world", got "${got}"`));
}
});
extra.on("data", (d) => {
got += d.toString();
});
extra.on("close", () => {
console.log("pipe closed");
});
extra.write("start");
await p.promise;
|