aboutsummaryrefslogtreecommitdiff
path: root/examples/spawn.ts
blob: ff53d84ea102b76e2669df1316cc618b2e3161e9 (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
import { readableStreamToText } from "bun";
import { spawn } from "bun";

const proc = spawn({
  cmd: ["ls", "-l"],

  // Both of these forms work:

  // as an array:
  stdio: ["ignore", "pipe", "ignore"],

  // You can also use "inherit" to inherit the parent's stdio.
  // stdin: "inherit",

  // You can pass a Bun.file to save it to a file:
  // stdout: Bun.file("/tmp/stdout.txt"),
});

const result = await readableStreamToText(proc.stdout);

await proc.exited();

console.log(result);