Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Command

25 exports Since v1.0.0 Source

Combinators

Since v1.0.0

Specify the environment variables that will be used when running this command.

By default, the configured variables extend the parent process environment. Set extendEnv to false to use only the configured variables.

Signature

declare const env: {
(environment: Record<string, string | undefined>, options?: {
readonly extendEnv?: boolean;
}): (self: Command) => Command;
(self: Command, environment: Record<string, string | undefined>, options?: {
readonly extendEnv?: boolean;
}): Command;
}
Since v1.0.0

Feed a string to standard input (default encoding of UTF-8).

Signature

declare const feed: {
(input: string): (self: Command) => Command;
(self: Command, input: string): Command;
}
Since v1.0.0

Flatten this command to a non-empty array of standard commands.

For a StandardCommand, this simply returns a 1 element array For a PipedCommand, all commands in the pipe will be extracted out into a array from left to right

Signature

declare const flatten: (self: Command) => NonEmptyReadonlyArray<StandardCommand>
Since v1.0.0

Pipe one command to another command from left to right.

Conceptually, the equivalent of piping one shell command to another:

Signature

declare const pipeTo: {
(into: Command): (self: Command) => Command;
(self: Command, into: Command): Command;
}

Example

Terminal window
command1 | command2

Allows for specifying whether or not a Command should be run inside a shell.

Signature

declare const runInShell: {
(shell: string | boolean): (self: Command) => Command;
(self: Command, shell: string | boolean): Command;
}
Since v1.0.0

Specify the standard error stream for a command.

Signature

declare const stderr: {
(stderr: CommandOutput): (self: Command) => Command;
(self: Command, stderr: CommandOutput): Command;
}
Since v1.0.0

Specify the standard input stream for a command.

Signature

declare const stdin: {
(stdin: CommandInput): (self: Command) => Command;
(self: Command, stdin: CommandInput): Command;
}
Since v1.0.0

Specify the standard output stream for a command.

Signature

declare const stdout: {
(stdout: CommandOutput): (self: Command) => Command;
(self: Command, stdout: CommandOutput): Command;
}

Set the working directory that will be used when this command will be run.

For piped commands, the working directory of each command will be set to the specified working directory.

Signature

declare const workingDirectory: {
(cwd: string): (self: Command) => Command;
(self: Command, cwd: string): Command;
}

Constructors

Since v1.0.0

Create a command with the specified process name and an optional list of arguments.

Signature

declare const make: (command: string, ...args: Array<string>) => Command

Execution

Since v1.0.0

Returns the exit code of the command after the process has completed execution.

Signature

declare const exitCode: (self: Command) => Effect<ExitCode, PlatformError, CommandExecutor>
Since v1.0.0

Runs the command returning the output as an array of lines with the specified encoding.

Signature

declare const lines: (command: Command, encoding?: string) => Effect<Array<string>, PlatformError, CommandExecutor>
Since v1.0.0

Start running the command and return a handle to the running process.

Signature

declare const start: (command: Command) => Effect<Process, PlatformError, CommandExecutor | Scope>
Since v1.0.0

Start running the command and return the output as a Stream.

Signature

declare const stream: (command: Command) => Stream<Uint8Array, PlatformError, CommandExecutor>

Runs the command returning the output as an stream of lines with the specified encoding.

Signature

declare const streamLines: (command: Command, encoding?: string) => Stream<string, PlatformError, CommandExecutor>
Since v1.0.0

Runs the command returning the entire output as a string with the specified encoding.

If an encoding is not specified, the encoding will default to utf-8.

Signature

declare const string: {
(encoding?: string): (command: Command) => Effect<string, PlatformError, CommandExecutor>;
(command: Command, encoding?: string): Effect<string, PlatformError, CommandExecutor>;
}

Models

Since v1.0.0

Signature

type Command = StandardCommand | PipedCommand
Since v1.0.0

Configures the pipe that is established between the parent and child processes' stdin stream.

Defaults to "pipe"

Signature

type CommandInput = "inherit" | "pipe" | Stream<Uint8Array, PlatformError>
Since v1.0.0

Configures the pipes that are established between the parent and child processes stderr and stdout streams.

Defaults to "pipe"

Signature

type CommandOutput = "inherit" | "pipe" | Sink<Uint8Array, Uint8Array>

PipedCommand

interface
Since v1.0.0

Signature

interface PipedCommand extends Proto {
readonly _tag: "PipedCommand";
readonly left: Command;
readonly right: Command;
}
Since v1.0.0

Signature

interface StandardCommand extends Proto {
readonly _tag: "StandardCommand";
readonly args: readonly Array<string>;
readonly command: string;
readonly cwd: Option<string>;
readonly env: HashMap<string, string>;
readonly extendEnv: boolean;
readonly gid: Option<number>;
readonly shell: string | boolean;
readonly stderr: CommandOutput;
readonly stdin: CommandInput;
readonly stdout: CommandOutput;
readonly uid: Option<number>;
}

Other

Since v1.0.0

Signature

declare const CommandTypeId: unique symbol
Since v1.0.0

Signature

type CommandTypeId = typeof CommandTypeId

Refinements

Returns true if the specified value is a Command, otherwise returns false.

Signature

declare const isCommand: (u: unknown) => u is Command