aboutsummaryrefslogtreecommitdiff
path: root/examples/spawn.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-25 13:08:51 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-25 13:08:51 -0700
commita4d46fc7db7459e3e7e895d3013ffe65b0f0078c (patch)
tree8c6d78f3ccc127b16ff38fe098223bd9b69c2736 /examples/spawn.ts
parent7ce4a4e3d3f5f06a1258eefc49ce1da166e43886 (diff)
downloadbun-jarred/subprocess.tar.gz
bun-jarred/subprocess.tar.zst
bun-jarred/subprocess.zip
Diffstat (limited to '')
-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);