# libtmux.Window.cmd

- **Module:** libtmux.Window
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/036c521c4b83ce6e434eb50afe2a0d08a6a05e46/src/libtmux/window.py#L461
- **Page:** https://libtmux.org/reference/py/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.

## Parameters

- `self`
- `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`

## Example

Create a pane from a window:

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

## Example

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