# libtmux.Server.run_shell

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py#L503
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-server-run_shell/

tmux command: [`run-shell`](/en/tmux/latest/manual/run-shell/)

```
libtmux.Server.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
```

Execute a shell command via [`$ tmux run-shell`](/en/tmux/latest/manual/run-shell/).

## Examples

```python
>>> 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).

## In other ports

### Run a shell command through tmux

- Ruby: [`LibTmux::Server#run`](/en/ruby/latest/reference/libtmux-server-run/) (method)
- TypeScript: [`server.Server.runShell`](/en/ts/latest/reference/server-server-runshell/) (method)
- Rust: [`server.Server.run_shell`](/en/rs/latest/reference/server-server-run_shell/) (method)
- Go: [`tmux.Server.RunShell`](/en/go/latest/reference/tmux-server-runshell/) (method)
- Java: [`io.github.libtmux.Shell.Shell.run`](/en/java/latest/reference/io-github-libtmux-shell-shell-run/) (method)
- C#: [`LibTmux.Server.RunShellAsync`](/en/csharp/latest/reference/libtmux-server-runshellasync/) (method)
- C++: [`libtmux::Server::run_shell`](/en/cxx/latest/reference/libtmux-server-run_shell/) (method)
