# libtmux.Window.cmd

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

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

Execute tmux subcommand within window context.

Automatically binds target by adding  ``-t`` for object's window ID to the
command. Pass ``target`` to keyword arguments to override.

## Examples

Create a pane from a window:

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

Magic, directly to a `Pane`:

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

## Parameters

- `cmd` (`str`)
- `args` (`t.Any`)
- `target` (`str | int | None`): Optional custom target override. By default, the target is the window ID.

## Returns

:meth:`server.cmd`

## In other ports

### Run a tmux command addressed at a window

- TypeScript: [`window.Window.cmd`](/en/ts/latest/reference/window-window-cmd/) (method)
- Rust: [`window.Window.cmd`](/en/rs/latest/reference/window-window-cmd/) (method)
- Go: [`tmux.Window.Cmd`](/en/go/latest/reference/tmux-window-cmd/) (method)
