# LibTmux\Invoke-TmuxPaneCommand

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/InvokeTmuxPaneCommandCommand.cs#L7
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-invoke-tmuxpanecommand/

```
Invoke-TmuxPaneCommand
    [-Pane] <LibTmux.Pane>
    [-Command] <System.String>
    [-Timeout <System.Double>]
    [-SuppressHistory <System.Boolean>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

Run a shell command in a native pane and report its exit status.

Run Command in a subshell in the selected pane and return a native
[`LibTmux.PaneRunResult`](/en/csharp/latest/reference/libtmux-panerunresult/). The result records the pane ID, authenticated shell
exit status, whether the wait timed out, elapsed time and effective timeout. A
nonzero exit status is a result, not a cmdlet error. The command does not change
the parent shell's working directory or environment.

A timeout returns `TimedOut = True` and a null [`ExitStatus`](/en/csharp/latest/reference/libtmux-panerunresult-exitstatus/); the command may
still be running. Cancellation after dispatch can leave it running too. Inspect
the pane before retrying either case. [`Output`](/en/csharp/latest/reference/libtmux-panerunresult-output/) contains bounded rendered command
output, which may include stdout and stderr together. It is not a byte-exact
process stream. Inspect `LinesMissed`, `AnchorLost` and omission counts before
treating it as complete. `Started = False` means no start marker was confirmed;
it does not prove the command never ran. The default view omits output text.
[Get-TmuxPaneContent](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Get-TmuxPaneContent.md) reads the current screen separately.

The pane must be a live, writable POSIX-compatible shell. [`-WhatIf`](/en/powershell/latest/reference/libtmux-invoke-tmuxpanecommand/#LibTmux%5CInvoke-TmuxPaneCommand.parameter.WhatIf) performs
no tmux I/O or input operation. Confirmation identifies the endpoint and pane
without displaying Command. A leading space is added to shell input by default;
shells configured to ignore space-prefixed history entries may omit it from
history. This is best effort.

### Notes

[`Tmux.PaneCommandFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Invoke-TmuxPaneCommand.md#notes) retains the pane as its target. The core reserves one
active command per pane in this process. A timed-out run keeps its reservation
until completion or an authenticated pane/server end; a second run is refused
while that command may still be active. A borrowed server is never removed.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Confirmation:** Supports `-WhatIf` and `-Confirm`; confirm impact: Medium.
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Pane`: The native pane selected from an explicit endpoint.
- **Outputs:** `LibTmux.PaneRunResult`

Related APIs:

- [Send input to a pane](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/input.md)

## Examples

Example 1

Given a native `$pane` running `/bin/sh` on an endpoint you own, inspect a
nonzero status without treating it as an operation failure:

[Source example](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Invoke-TmuxPaneCommand.md).

```powershell
$pane |
    LibTmux\Invoke-TmuxPaneCommand -Command 'exit 7' -Timeout 5 -Confirm:$false
```

The result has `ExitStatus = 7` and `TimedOut = False`.

## Parameters

- `Pane` (`LibTmux.Pane`): The native pane from the endpoint you intend to change.
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Command` (`System.String`): The shell command to run in a subshell. Empty, whitespace-only and NUL-containing
commands are rejected. The core accepts at most 64 KiB of UTF-8 input.
  Required. Position 1. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Timeout` (`System.Double`): The completion wait in seconds. Fractions are accepted. The default is 30;
the valid range is 0.0000001 through 86400. NaN and infinity are rejected.
Cleanup after an observed result may take additional time.
  Optional. Named parameter. Does not accept pipeline input. Documented default: `30`.
- `SuppressHistory` (`System.Boolean`): Add a leading space to the shell input. Defaults to True. Set to False to
omit the prefix; shell history behavior still depends on the shell and its
configuration.
  Optional. Named parameter. Does not accept pipeline input. Documented default: `True`.
- `Verbose` (`System.Management.Automation.SwitchParameter`): Display verbose messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `vb`.
- `Debug` (`System.Management.Automation.SwitchParameter`): Display debug messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `db`.
- `ErrorAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to non-terminating errors.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ea`.
- `WarningAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to warning messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wa`.
- `InformationAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles information messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `infa`.
- `ProgressAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles progress updates.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `proga`.
- `ErrorVariable` (`System.String`): Store the command's error records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ev`.
- `WarningVariable` (`System.String`): Store the command's warning records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wv`.
- `InformationVariable` (`System.String`): Store the command's information records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `iv`.
- `OutVariable` (`System.String`): Save output in the named variable while passing it down the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ov`.
- `OutBuffer` (`System.Int32`): Buffer output before passing it to the next pipeline command.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ob`.
- `PipelineVariable` (`System.String`): Make the most recent output object available through a named variable within the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `pv`.
- `WhatIf` (`System.Management.Automation.SwitchParameter`): Describe the intended command without sending it or acquiring fresh tmux state.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Prompt before sending the command. The prompt does not show Command.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.

## Returns

`LibTmux.PaneRunResult`: One result per pane with exit status or a timeout indication.
