aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/spawned-child.js
blob: 263c566f98d53b5fdd795795b7a4f4565d984c63 (plain) (blame)
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
const TARGET = process.argv[2];
const MODE = process.argv[3];

if (TARGET === "STDIN") {
  let data = "";
  process.stdin.setEncoding("utf8");
  if (MODE === "READABLE") {
    process.stdin.on("readable", () => {
      let chunk;
      while ((chunk = process.stdin.read()) !== null) {
        data += chunk;
      }
    });
  } else {
    process.stdin.on("data", chunk => {
      data += chunk;
    });
  }
  process.stdin.on("end", () => {
    process.stdout.write("data: ");
    process.stdout.write(data);
  });
} else if (TARGET === "STDOUT") {
  process.stdout.write("stdout_test");
} else if (TARGET === "ERROR") {
  console.log("oops");
} else {
  // nothing
}