# libtmux.Server.cmd

- **Module:** libtmux.Server
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/server.py#L340
- **Page:** https://libtmux.org/reference/py/libtmux-server-cmd/

```
libtmux.Server.cmd(self, cmd: str, args: t.Any, target: str | int | None = None, timeout: float | None = None) -> tmux_cmd
```

Execute tmux command respective of socket name and file, return output.

## Parameters

- `self`
- `cmd` (str)
- `args` (t.Any)
- `target` (str | int | None) — Optional custom target.
- `timeout` (float | None)

## Returns

:class:`common.tmux_cmd`

## Example

```python
>>> server.cmd('display-message', 'hi')
<libtmux.common.tmux_cmd object at ...>
```

## Example

New session:

```python
>>> server.cmd('new-session', '-d', '-P', '-F#{session_id}').stdout[0]
'$2'
```

## Example

```python
>>> session.cmd('new-window', '-P').stdout[0]
'libtmux...:2.0'
```

## Example

Output of `tmux -L ... new-window -P -F#{window_id}` to a `Window` object:

```python
>>> Window.from_window_id(window_id=session.cmd(
... 'new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)
Window(@4 3:..., Session($1 libtmux_...))
```

## Example

Create a pane from a window:

```python
>>> window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0]
'%5'
```

## Example

Output of `tmux -L ... split-window -P -F#{pane_id}` to a `Pane` object:

```python
>>> Pane.from_pane_id(pane_id=window.cmd(
... 'split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server)
Pane(%... Window(@... ...:..., Session($1 libtmux_...)))
```
