Core Library0.xAPI Reference

Choose documentation 3

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.

method libtmux latest

Server.run_shell

Execute a shell command via $ tmux run-shell.

Source and package
Qualified name
libtmux.Server.run_shell
Module
libtmux
Declared in
Server
Package
libtmux
Source
src/libtmux/server.py
Other languages
Perl Erlang PowerShell Julia Elixir Haskell Common Lisp Ruby Lua TypeScriptRustGoJavaC#C++ Swift Kotlin Scala OCaml F# Clojure
run_shell ( self, command: str, background: bool | None = None, delay: str | None = None, as_tmux_command: bool | None = None, target_pane: str | None = None, cwd: StrPath | None = None, show_stderr: bool | None = None, args: list[str] | None = None, ) → list[str] | None

Examples#

>>> result = server.run_shell('true')
>>> isinstance(result, list)
True
Parameters
  • command (str) # – Shell command to execute.

  • background (bool | None) # – Run in background (-b flag).

  • delay (str | None) # – Delay before execution (-d flag).

  • as_tmux_command (bool | None) # – Parse argument as a tmux command instead of a shell command (-C flag).

  • target_pane (str | None) # – Target pane for output (-t flag).

  • cwd (StrPath | None) # – Start directory for the shell command (-c flag). When omitted, tmux uses the target client's current working directory. Requires tmux 3.4+; on older tmux a warning is emitted and the kwarg is ignored. Note: tmux's -c is a start directory, not subprocess semantics. If chdir(cwd) fails, tmux falls back to the user's home directory, then to /, rather than raising — unlike Python's subprocess.Popen(cwd=) which errors on a failed chdir. added 0.57

  • show_stderr (bool | None) # – Combine the command's stderr into the captured output stream (-E flag, maps to JOB_SHOWSTDERR). Requires tmux 3.6+; on older tmux a warning is emitted and the kwarg is ignored. added 0.57

  • args (list[str] | None) # – Positional arguments passed after command, expanded as #{1}, #{2}, … inside it. Requires tmux 3.7+; warns and is ignored on older tmux.

Returns

list[str] | None Stdout lines, or None when background is True. Empty list on tmux 3.3a/3.4 (upstream stdout passthrough was broken until 3.5).

tmux command#

The tmux commands behind run_shell.

tmux C API#

The C declarations in tmux that implement these commands.

In other ports#

Run a shell command through tmux

Equivalents of Run a shell command through tmux in other languages
Language Equivalent
Ruby LibTmux::Server#run
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
TypeScript server.Server.runShell
Rust server.Server.run_shell
Go tmux.Server.RunShell
Java io.github.libtmux.Shell.run
C# LibTmux.Server.RunShellAsync
C++ libtmux::Server::run_shell
Swift Server.run(_:in:) types a command into a pane rather than running it on the host
OCaml No direct public OCaml equivalent is recorded for this operation.
Perl No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands.

No equivalent is recorded in Lua, PowerShell, Julia, Erlang, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Esc

Type to search.

Reference previewOpen reference