Get a session handle, send a command to a pane, and capture output. These examples use libtmux from your program; to attach your terminal interactively, see Attaching to tmux.
Select your port below. The examples retain their source’s setup, error handling, and cleanup, so the operations shown vary by port. Where this comes from identifies each source and its test coverage.
Finding an existing session insteadLink to section
For a script that runs repeatedly, look up a session before creating it. Attaching to tmux shows that pattern, and Filtering and querying, in practice covers absent and ambiguous matches.
Where this comes fromLink to section
PythonLink to section
Source: src/libtmux/server.py, session.py, pane.py docstrings
In this page: hand-quoted, composed from three separate docstrings
Checked by: pytest runs every >>> doctest (testpaths includes
src/libtmux) against a real, isolated tmux session on every test run
TypeScriptLink to section
Source: examples/quickstart/quickstart.ts
In this page: read whole from the file
Checked by: run against real tmux by bun test examples; its first half is
also mirrored into README.md under a <!-- runs: ... --> marker, checked
line-for-line by scripts/check-doc-runnable.ts
RustLink to section
Source: crates/libtmux/examples/scratch.rs
In this page: read whole from the file
Checked by: run to completion against a throwaway tmux by
scripts/run-examples.sh (just examples), which CI runs and which also
asserts the example leaves no session behind
GoLink to section
Source: examples/quickstart/main.go
In this page: read whole from the file
Checked by: the whole file runs against a real tmux server as
TestQuickstart; the docs:quickstart region inside it is additionally
mirrored into README.md by go generate ./tmux, and CI fails if the two drift
JavaLink to section
Source:
examples/src/main/java/io/github/libtmux/examples/BuildAWorkspace.java
In this page: read whole from the file
Checked by: run against real tmux by the examples module’s own
ExamplesRunTest
.NETLink to section
Source: examples/LibTmux.Examples/Snippets/OneShot.cs
In this page: read whole from the file
Checked by: its ConnectAndBuild region is mirrored into README.md and
checked by sync_snippets.py --check; the mirrored csharp run block is
additionally compiled and run by ReadmeExampleTests
C++Link to section
Source: examples/05-readme.cpp, the connect and build regions
In this page: Copied excerpts from the connect and build regions.
Checked by: quoted verbatim into README.md, checked for drift by
tools/docs/check_readme.py, and the whole file is built and run by CTest
SwiftLink to section
Source: Examples/Sources/ExampleCode/Changing.swift
In this page: read whole from the file
Checked by: matched against the README’s “Change what is there” section by
Scripts/check_examples.py; compiled and run through the package’s public
products by swift test --package-path Examples
Source inclusionLink to section
A file="..." fence reads the named source during the site build. Hand-quoted
excerpts are copies; their source files and regions are listed above.