Skip to content

shell ​

Run child processes.

Import

ts
import { ShellResult, ShellProcess, Shell } from "shell";

Needs the "shell" permission in thicket.json.

ShellResult class ​

ts
class ShellResult

ShellResult.exitCode ​

ts
exitCode: int

Exit code of the child process.

ShellResult.ok ​

ts
ok: boolean

True if exitCode is 0.

ShellResult.stderr ​

ts
stderr: string

Standard error output from the child process.

ShellResult.stdout ​

ts
stdout: string

Standard output from the child process.

ShellProcess class ​

ts
class ShellProcess

ShellProcess.kill ​

ts
kill(signal?: string): void

Send a signal to the child process. signal defaults to "SIGTERM"; recognized signals include "SIGTERM", "SIGKILL", "SIGSTOP", "SIGCONT", "SIGINT".

Parameters

  • signal: Signal name as a string; defaults to "SIGTERM".

ShellProcess.on ​

ts
on(event: string, handler: any): void

Register an event handler. Recognized events: "exit" (passes exit code), "stdout" (passes accumulated stdout data), "stderr" (passes accumulated stderr data).

Parameters

  • event: Event name: "exit", "stdout", or "stderr".
  • handler: Callback; receives the event data (exit code as int, or data as string).

Shell static class ​

ts
static class Shell

Shell.exec ​

ts
static exec(cmd: string, opts?: any): any

Execute a command synchronously and return a Promise<ShellResult>. The command string is parsed (no shell expansion; supports single and double quotes and backslash escapes). Options may include cwd (working directory) and timeout (milliseconds).

Parameters

  • cmd: Command string to parse and execute.
  • opts: Optional {cwd?: string, timeout?: int}.

Returns: Promise that resolves to a ShellResult when the process exits.

Shell.spawn ​

ts
static spawn(cmd: string): any

Spawn a child process and return a ShellProcess handle (Unix/Linux only). The command string is parsed the same way as exec. Output is streamed to handlers registered via process.on("stdout"|"stderr"|"exit", ...).

Parameters

  • cmd: Command string to parse and execute.

Returns: ShellProcess; use .on() to listen for output and exit.


Generated from lang/types/shell.d.tks in the ThicketScript repository.