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
-
Description#
No shell parses
argv:["echo", "$HOME"]prints$HOME, andcdor a pipe needs["sh", "-c", …]. The program gets a real terminal, so a full-screen program can be driven by keys;SpawnOptionssays what that means for pagers and prompts.The
Programowns its pane, in a detached session of its own unlessfromplaces it beside another pane:await usingorProgram.killends the program and removes it, and tmux does once this process stops renewing its lease, unlessorphanAfterMsisnull. 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 withPane.waitForTextbefore typing.Requires tmux 3.8 or newer, and raises
VersionTooLowErrorbelow it. Earlier releases have no exit event to wait on, and through 3.7c a dead pane never closes the pipestreamreads.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