The @effect/platform/Command module provides a way to create and run commands with the specified process name and an optional list of arguments.
Creating Commands
The Command.make function generates a command object, which includes details such as the process name, arguments, and environment.
Example
This command object does not execute until run by an executor.
Running Commands
You need a CommandExecutor to run the command, which can capture output in various formats such as strings, lines, or streams.
Example
Output Formats
Method
Description
string
Runs the command returning the output as a string (with the specified encoding)
lines
Runs the command returning the output as an array of lines (with the specified encoding)
stream
Runs the command returning the output as a stream of Uint8Array chunks
streamLines
Runs the command returning the output as a stream of lines (with the specified encoding)
exitCode
If all you need is the exit code of the command, you can use the Command.exitCode function.
Example
Custom Environment Variables
You can customize environment variables in a command by using Command.env. This is useful when you need specific variables for the command’s execution.
Example
In this example, the command runs in a shell to ensure environment variables are correctly processed.
Standard Input
You can send input directly to a command’s standard input using the Command.feed function.
Example
Fetching Process Details
Next, we show how to obtain details about a running process like exitCode, stdout, and stderr.
Streaming stdout to process.stdout
In some cases, you may want to run a command and stream its stdout directly to process.stdout. Here’s how: