libtmux
English
Reference MCP Search

Capture pane output

Edit this page on GitHub

The other half of Attach and send keys: reading what a pane printed, and — since tmux accepts a command before the shell running it has necessarily finished (see Sending keys) — waiting for the right moment to read rather than reading immediately or sleeping a guessed amount. Capturing output is the guide-level discussion of why each pattern below exists; this page is the sourced code behind it — see the table at the end for exactly which file each block came from and how it’s checked.

Read what’s on screenLink to section

>>> pane = window.split(shell='sh')
>>> pane.capture_pane()
['$']
>>> pane.send_keys('echo "Hello world"', enter=True)
>>> pane.capture_pane()
['$ echo "Hello world"', 'Hello world', '$']

Wait for text instead of guessing a delayLink to section

Python’s checked wait is wait_for, tmux’s own signal channel, rather than a helper that scrapes pane text for a pattern — no checked helper that waits on pane text was found in the source for this page.

>>> server.new_session(session_name='wait_test')
Session(...)
>>> server.wait_for('test_channel', set_flag=True)

waitForOutput takes patterns for both success and failure, so a process that fails fast is discovered immediately rather than by timing out.

Where this comes fromLink to section

PortSourceIn this pageChecked by
Pythonsrc/libtmux/pane.py (capture_pane), src/libtmux/server.py (wait_for) docstringshand-quotedpytest runs every >>> doctest against a real, isolated tmux session on every test run
TypeScriptexamples/capture/capture.ts (read), examples/agent/agent.ts (wait)read whole from each fileboth run against real tmux by bun test examples; agent.ts is additionally mirrored into README.md under a <!-- runs: ... --> marker checked by scripts/check-doc-runnable.ts
Goexamples/quickstart/main.go (read, already shown whole on the previous page), examples/control-mode-subscribe/main.go (wait)read: hand-quoted; wait: read whole from the fileboth run against real tmux as TestQuickstart / TestControlModeSubscribe; the wait file’s docs:watching region is additionally mirrored into README.md by go generate ./tmux
Rustcrates/libtmux/examples/scratch.rs, already shown whole on the previous pagehand-quoted excerpts of the same filerun to completion against a throwaway tmux by scripts/run-examples.sh, which CI runs
Javaroot README.md Quickstart (read), examples/src/main/java/io/github/libtmux/examples/WatchPaneOutput.java (wait)read: hand-quoted; wait: read whole from the fileevery README fence is compiled and run against real tmux by docs-tests; WatchPaneOutput is additionally run by the examples module’s ExamplesRunTest
.NETroot README.md, “Running something, and reading it back”hand-quotedone of the csharp run blocks compiled and run against real tmux by ReadmeExampleTests
C++examples/05-readme.cpp capture region (read); include/libtmux/server.hpp doc comment (wait, no fence)hand-quotedthe capture region is quoted verbatim into README.md and checked by tools/docs/check_readme.py; the whole file is built and run by CTest
SwiftExamples/Sources/ExampleCode/Changing.swift (read, already shown whole on the previous page), Waiting.swift (wait)read: hand-quoted excerpt; wait: read whole from the fileboth matched against the README by Scripts/check_examples.py and run by swift test --package-path Examples

Go, Rust, and Swift each reuse a file already shown in full on Attach and send keys: rather than dump the same file a second time, this page quotes just the relevant lines by hand, with a comment naming the source, and points back at the full listing there.

Esc

Type to search.