Core Library0.xAPI reference

Choose documentation 1

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

MoreLess about this notice

function libtmux-fsharp

Pane.run

Runs a shell command in the pane and waits for its exit status and output.

Source and package
Qualified name
LibTmux.FSharp.Pane.run
Namespace
LibTmux.FSharp
Declared in
Pane
Package
LibTmux.FSharp
Source
src/LibTmux.FSharp/Hierarchy.fsi
F# value signaturesDeclares the name and type of a value or function in a signature.Language documentation run: cancellationToken: CancellationToken -> timeout: TimeSpan -> command: string -> pane: LibTmux.Pane -> Task<PaneRunResult>

Description

The pane must sit at a POSIX shell prompt. A command still running at the timeout keeps running; the result reports TimedOut. A command that prints more than scrollback holds reports LinesMissed, and its Output is then what the pane still showed.

Parameters
Errors
  • LibTmux.TmuxPaneException – The pane is in a mode, not running a POSIX shell, or its program has exited; or it changed during every read before the command was sent.

  • LibTmux.TmuxObjectNotFoundException – tmux no longer has the pane.

  • LibTmux.LibTmuxException – The command was sent and the run was cancelled or could not be observed; TmuxFailure.MayHaveRun matches it, and the pane needs inspecting before a retry.

Examples

Type a line and wait for what it prints, not for its echo. Wait for a condition over the whole screen, then run a command and read its exit status and output. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as Example.fsproj. It references the 0.1.1 release of LibTmux.FSharp on NuGet: View source

Example.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<PackageReference Include="FSharp.Core" Version="[10.1.303]" />
<PackageReference Include="LibTmux.FSharp" Version="[0.1.1]" />
</ItemGroup>
</Project>

Save this complete program as Program.fs. It creates a private server with LibTmux.Server.CreateOwnedAsync; use! disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View source

Program.fsComplete program
// fsharp-snippet: SendWaitRead
open System
open System.IO
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 20.)
let token = deadline.Token
let socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"
use _cleanup =
{ new IDisposable with
member _.Dispose() = socketRoot.Delete true
}
let options =
ServerConnectionOptions(
SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),
ConfigurationFile = "/dev/null"
)
use! owned = options |> Server.createOwned token
let! session =
owned.Value |> Server.newSession token (SessionSpec.running "work" "/bin/sh")
let! pane = session |> Session.activePane token
// Type a line and wait for what it prints. The screen before it and
// the line's own echo do not count.
let! ready =
pane
|> Pane.sendAndWait token (TimeSpan.FromSeconds 5.) "echo server ready" "server ready"
// A condition sees every visible row each time the pane changes.
do! pane |> Pane.sendLine token "seq 3"
let! counted =
pane
|> Pane.waitUntil token (TimeSpan.FromSeconds 5.) (fun rows -> rows |> Seq.exists ((=) "3"))
// Running a command waits for its exit status and returns its output.
let! listing =
pane |> Pane.run token (TimeSpan.FromSeconds 10.) "printf 'a\\nb\\n'; exit 4"
let! screen = pane |> Pane.capture token (CapturePaneRequest())
// One case for each way a wait can end; leaving one out draws a warning.
let describe wait =
match wait with
| PaneWait.Found -> "found"
| PaneWait.Printed -> "printed"
| PaneWait.Stopped pattern -> "stopped by " + pattern
| PaneWait.TimedOut -> "timed out"
| PaneWait.Ended -> "the pane's program ended"
printfn "ready: %s" (describe ready)
printfn "counted: %s" (describe counted)
match listing with
| PaneRun.Exited status -> printfn "run: exit %d, output %A" status (List.ofSeq listing.Output)
| PaneRun.Ended -> printfn "run: the shell exited first"
| PaneRun.NotStarted -> printfn "run: the shell was not at a prompt"
| PaneRun.TimedOut -> printfn "run: still running"
printfn "screen shows the run: %b" (screen |> Seq.exists (fun row -> row = "a"))
}
runAsync().GetAwaiter().GetResult()
// endfsharp-snippet

Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:

Terminal window
$ dotnet build Example.fsproj --configuration Release && \
dotnet bin/Release/net8.0/Example.dll && \
dotnet bin/Release/net10.0/Example.dll

Expected program output from each framework:

ready: found
counted: found
run: exit 4, output ["a"; "b"]
screen shows the run: true

Recorded calls

source calls
No call edges in the F# model.

The F# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.FSharp.Pane.run.

Guides

task material

Pages that discuss run.

Esc
Search in

Type to search.

Reference previewOpen reference