From 2b9035032de0b7062793d0174ef36e71524e51a2 Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Tue, 28 May 2024 21:10:45 +0200 Subject: [PATCH] chore: Update platform README with example for streaming stdout (#2870) --- packages/platform/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/platform/README.md b/packages/platform/README.md index 67978e0692..9222012df2 100644 --- a/packages/platform/README.md +++ b/packages/platform/README.md @@ -255,6 +255,25 @@ NodeRuntime.runMain( ) ``` +## Running a Platform Command with stdout Streamed to process.stdout + +To run a command (for example `cat`) and stream its `stdout` to `process.stdout` follow these steps: + +```ts +import { Command } from "@effect/platform" +import { NodeContext, NodeRuntime } from "@effect/platform-node" +import { Effect } from "effect" + +// Create a command to run `cat` on a file and inherit stdout +const program = Command.make("cat", "./some-file.txt").pipe( + Command.stdout("inherit"), + Command.exitCode +) + +// Run the command using NodeRuntime with the NodeContext layer +NodeRuntime.runMain(program.pipe(Effect.provide(NodeContext.layer))) +``` + # FileSystem The `@effect/platform/FileSystem` module provides a single `FileSystem` tag, which acts as the gateway for interacting with the filesystem.