aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/spawn.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/spawn.ts b/examples/spawn.ts
new file mode 100644
index 000000000..c29cc4f21
--- /dev/null
+++ b/examples/spawn.ts
@@ -0,0 +1,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.exitStatus;
+
+console.log(result);