# server.Server.spawn

- **Module:** server
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ts/blob/ad09eaef7ffff40f510989ee0695852c44a31576/packages/libtmux/src/server.ts#L1482
- **Page:** https://libtmux.org/en/ts/latest/reference/server-server-spawn/

```
async spawn(
  argv: readonly string[],
  options?: SpawnOptions,
): Promise<Program>
```

Start a program in a pane of its own and return it running.

No shell parses [`argv`](/en/ts/latest/reference/types-plannedoperation-argv/): `["echo", "$HOME"]` prints `$HOME`, and `cd` or
a pipe needs `["sh", "-c", …]`. The program gets a real terminal, so a
full-screen program can be driven by keys; [`SpawnOptions`](/en/ts/latest/reference/types-spawnoptions/) says what
that means for pagers and prompts.

The [`Program`](/en/ts/latest/reference/program-program/) owns its pane, in a detached session of its own
unless `from` places it beside another pane: `await using` or
[`Program.kill`](/en/ts/latest/reference/program-program-kill/) ends the program and removes it, and tmux does once
this process stops renewing its lease, unless [`orphanAfterMs`](/en/ts/latest/reference/types-spawnoptions-orphanafterms/) is [`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null).
Like a child process, a running program keeps this process alive until it
ends.

Keys go to the terminal at once. A program that reads lines, like `cat`,
reads them when it gets there; a full-screen one, like vim, can drop keys
that arrive before it has set up its terminal, so wait for its first
screen with [`Pane.waitForText`](/en/ts/latest/reference/pane-pane-waitfortext/) before typing.

Requires tmux 3.8 or newer, and raises [`VersionTooLowError`](/en/ts/latest/reference/errors-versiontoolowerror/)
below it. Earlier releases have no exit event to wait on, and through
3.7c a dead pane never closes the pipe [`stream`](/en/ts/latest/reference/program-program-stream/) reads.

## Examples

```ts
await using cat = await server.spawn(["cat"]);
await cat.pane.sendKeys("hello");
await cat.pane.sendKeys("C-d", { enter: false });
const { exitCode } = await cat.wait(); // 0
```

## Parameters

- `argv` (`readonly string[]`)
- `options?` (`SpawnOptions`)
