Skip to main content
The glide.process API provides methods for spawning and managing external processes from within Glide.

Methods

spawn()

Spawn a new process. The given command can either be the name of a binary in the PATH or an absolute path to a binary file.
const proc = await glide.process.spawn(
  command: string,
  args?: string[] | null | undefined,
  opts?: glide.SpawnOptions
): Promise<glide.Process>
command
string
required
The command to execute. Can be a binary name in PATH or an absolute path.
args
string[]
Arguments to pass to the command.
opts
glide.SpawnOptions
Options for spawning the process.
Process
glide.Process
A process object with methods to interact with the spawned process.
On macOS, the PATH environment variable may not be set to what you expect, as applications don’t inherit your shell environment. You can update it with glide.env.set("PATH", "/usr/bin:/usr/local/bin").
Example: Basic process spawning
const proc = await glide.process.spawn('ls', ['-la']);
const output = await proc.stdout.text();
console.log(output);
Example: Open terminal with editor
const proc = await glide.process.spawn(
  'kitty',
  ['nvim', 'glide.ts'],
  { cwd: '~/.dotfiles/glide' }
);
console.log('Opened kitty with pid', proc.pid);
Example: Custom environment variables
const proc = await glide.process.spawn('printenv', [], {
  env: { 'MY_VAR': 'custom_value' }
});
const output = await proc.stdout.text();
Example: Process with stdin interaction
const proc = await glide.process.spawn('cat');
await proc.stdin.write('Hello from stdin!\n');
proc.stdin.close();

const reader = proc.stdout.getReader();
const { value } = await reader.read();
console.log(value); // "Hello from stdin!\n"

await proc.wait();
Example: Stream processing
const proc = await glide.process.spawn('sh', [
  '-c',
  'echo first; sleep 0.1; echo second'
]);

for await (const line of proc.stdout.lines()) {
  console.log('Line:', line);
}
Example: Handle non-zero exit codes
try {
  const proc = await glide.process.spawn('false');
  await proc.wait();
} catch (err) {
  if (err instanceof GlideProcessError) {
    console.log('Exit code:', err.exit_code);
    console.log('Process:', err.process);
  }
}

// Or disable exit code checking
const proc = await glide.process.spawn('false', [], {
  check_exit_code: false
});
await proc.wait();
console.log('Exit code:', proc.exit_code);

execute()

Spawn a new process and wait for it to exit. This is a convenience method that combines spawn() and wait().
const proc = await glide.process.execute(
  command: string,
  args?: string[] | null | undefined,
  opts?: glide.SpawnOptions
): Promise<glide.CompletedProcess>
command
string
required
The command to execute.
args
string[]
Arguments to pass to the command.
opts
glide.SpawnOptions
Same options as spawn().
CompletedProcess
glide.CompletedProcess
A process object that has already exited (guaranteed to have a non-null exit_code).
Example
const proc = await glide.process.execute('pwd');
console.log('Exit code:', proc.exit_code);
const output = await proc.stdout.text();
console.log('Current directory:', output.trim());

Types

glide.Process

Represents a running or completed process.
type Process = {
  pid: number;
  exit_code: number | null;
  stdout: glide.ProcessReadStream;
  stderr: glide.ProcessReadStream | null;
  stdin: glide.ProcessStdinPipe;
  wait(): Promise<glide.CompletedProcess>;
  kill(timeout?: number): Promise<glide.CompletedProcess>;
}

glide.CompletedProcess

Represents a process that has exited.
type CompletedProcess = glide.Process & { exit_code: number }

glide.ProcessReadStream

A ReadableStream with helper methods for processing output.
type ProcessReadStream = ReadableStream<string> & {
  text(): Promise<string> & { [Symbol.asyncIterator](): AsyncIterator<string> };
  lines(): Promise<string[]> & { [Symbol.asyncIterator](): AsyncIterator<string> };
}

glide.ProcessStdinPipe

Write interface for process stdin.
type ProcessStdinPipe = {
  write(data: string | ArrayBuffer | TypedArray): Promise<void>;
  close(opts?: { force?: boolean }): Promise<void>;
}

GlideProcessError

Thrown when a process exits with a non-zero exit code (when check_exit_code is true).
class GlideProcessError extends Error {
  name: 'GlideProcessError';
  exit_code: number;
  process: glide.Process;
}

Build docs developers (and LLMs) love