Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.PlatformService
open Axial.ProcessStreaming output
Use Process.stream when a process's output is part of the workflow, rather than something to inspect after the process exits. It returns a FlowStream, not a Flow.
Show page setup
// Setup for the checked examples on this page.
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.PlatformService
open Axial.Process
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actual// The examples on this page start real processes with the live service.
let host : ProcessHostEnvironment =
{ Process = Process.live Clock.live FileSystem.live Console.live
Console = Console.live }
host: ProcessHostEnvironmentAxial.Process.ProcessHostEnvironmentThe live environment used by <c>Process.run</c> at a command-line host boundary. Application workflows normally use their own environment record and <c>Process.runWith</c>.
Process: IProcessAxial.Process.ProcessModulelive: IClock -> IFileSystem -> IConsole -> IProcessCreates a live process service using an explicit clock for transcript timestamps and durations.
Axial.PlatformService.ClockHelpers for the clock service.
live: IClockCreates a live clock backed by and a monotonic timer.
Axial.FileSystem.FileSystemModulelive: IFileSystemCreates a live file-system service backed by , , and .
Axial.Console.ConsoleModulelive: IConsoleCreates a live console service backed by .
Console: IConsolelet events =
Process.command $"printf 'ready\nsample 1\n'"
|> Process.framing OutputFraming.Lines
|> Process.stream
events: FlowStream<ProcessHostEnvironment,ProcessError,ProcessEvent>Axial.Process.ProcessModulecommand: FormattableString -> ProcessSpecCreates a safely tokenized one-command process specification from an interpolated command template. Each interpolation hole is one native argument. Example: Process.command $"git show {revision}" |> Process.toFlow
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
framing: OutputFraming -> ProcessSpec -> ProcessSpecSelects chunk or line event framing. Example: specification |> Process.framing OutputFraming.Lines
Axial.Process.OutputFramingSelects arbitrary decoded chunks or complete decoded lines for streamed events.
Linesstream: ProcessSpec -> FlowStream<'env,ProcessError,ProcessEvent>Streams process events in the current Flow runtime. The last event is <c>Completed</c>.
With OutputFraming.Lines, each ProcessEvent.Output contains one decoded line. OutputFraming.Chunks preserves arbitrary decoded chunks. Every output value identifies its stage, stdout or stderr channel, and timestamp. The final event is always ProcessEvent.Completed result.
Handle events as they arrive
Use ordinary FlowStream combinators to take, filter, transform, or collect events:
let report event =
match event with
| ProcessEvent.Output output -> $"[{output.Channel}] {output.Text}"
| ProcessEvent.Completed result -> $"exit code: {result.ExitCode}"
let reports : Flow<ProcessHostEnvironment, ProcessError, string list> =
events
|> FlowStream.map report
|> FlowStream.runCollect
report: ProcessEvent -> stringevent: ProcessEventAxial.Process.ProcessEventValues emitted by a native process FlowStream.
Outputoutput: ProcessOutputCompletedresult: ProcessResultreports: Flow<ProcessHostEnvironment,ProcessError,string list>Axial.Flow`3Represents a cold workflow that reads an environment, returns a typed result, and is executed explicitly through one of its execution members such as ToTask, ToAsync, or RunSynchronously. The type of the environment dependency. The type of the failure value. The type of the success value.
Axial.Process.ProcessHostEnvironmentThe live environment used by <c>Process.run</c> at a command-line host boundary. Application workflows normally use their own environment record and <c>Process.runWith</c>.
Axial.Process.ProcessErrorA recoverable process startup, timeout, stage, or I/O failure. Interrupting the workflow is not an error: it terminates the processes and surfaces as <c>Cause.Interrupt</c>.
stringAn abbreviation for the CLI type . Basic Types
listThe type of immutable singly-linked lists. See the module for further operations related to lists. Use the constructors [] and :: (infix) to create values of this type, or the notation [1; 2; 3]. Use the values in the List module to manipulate values of this type, or pattern match against the values directly. See also F# Language Guide - Lists.
events: FlowStream<ProcessHostEnvironment,ProcessError,ProcessEvent>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.FlowStreamModulemap: ('v -> 'w) -> FlowStream<'env,'error,'v> -> FlowStream<'env,'error,'w>Transforms the successful values of a stream using the provided function. The function to transform each value. The stream whose values should be transformed. A new stream that yields transformed values. let stream = FlowStream.fromSeq [1; 2; 3] |> FlowStream.map (fun n -> n * 2)
runCollect: FlowStream<'a,'b,'c> -> Flow<'a,'b,'c list>Collects all emitted values into a list. stream |> FlowStream.runCollect
reports |> Flow.run host |> shouldEqual (Exit.Success [ "[StdOut] ready"; "[StdOut] sample 1"; "exit code: 0" ])
reports: Flow<ProcessHostEnvironment,ProcessError,string list>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Flowrun: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
host: ProcessHostEnvironmentshouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
The stream is backpressured: Axial does not buffer unbounded events while the consumer is busy. Stopping consumption early interrupts the producer Flow and terminates the native process topology before the enclosing scope closes.
Stream versus console forwarding
Use DSL console, or configure both channels with Process.stdout and Process.stderr, when output only needs to be visible. That path returns a normal Flow that completes with ProcessResult. Use Process.stream when output itself drives workflow decisions.

