Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-ts latest

Server.spawn

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

Source and package
Qualified name
Server.spawn
Module
server
Declared in
Server
Package
libtmux
Source
packages/libtmux/src/server.ts
async spawn( argv: readonly string[], options?: SpawnOptions, ): Promise<Program>

Description#

No shell parses 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 says what that means for pagers and prompts.

The Program owns its pane, in a detached session of its own unless from places it beside another pane: await using or Program.kill ends the program and removes it, and tmux does once this process stops renewing its lease, unless orphanAfterMs is 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 before typing.

Requires tmux 3.8 or newer, and raises VersionTooLowError below it. Earlier releases have no exit event to wait on, and through 3.7c a dead pane never closes the pipe stream reads.

Examples#

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
Esc

Type to search.

Reference previewOpen reference