Skip to main content
Deno.Process - Deno documentation
class Deno.Process
Deprecated

This will be removed in Deno 2.0. See the Deno 1.x to 2.x Migration Guide for migration instructions.

Represents an instance of a sub process that is returned from Deno.run which can be used to manage the sub-process.

Type Parameters

T extends RunOptions = RunOptions

Properties

readonly
pid: number

The operating system's process ID for the sub-process.

readonly
rid: number

The resource ID of the sub-process.

readonly
stderr: T["stderr"] extends "piped" ?
Reader
& Closer
& { readable: ReadableStream<Uint8Array>; }
: (
Reader
& Closer
& { readable: ReadableStream<Uint8Array>; }
) | null

A reference to the sub-processes stderr, which allows interacting with the sub-process at a low level.

readonly
stdin: T["stdin"] extends "piped" ?
Writer
& Closer
& { writable: WritableStream<Uint8Array>; }
: (
Writer
& Closer
& { writable: WritableStream<Uint8Array>; }
) | null

A reference to the sub-processes stdin, which allows interacting with the sub-process at a low level.

readonly
stdout: T["stdout"] extends "piped" ?
Reader
& Closer
& { readable: ReadableStream<Uint8Array>; }
: (
Reader
& Closer
& { readable: ReadableStream<Uint8Array>; }
) | null

A reference to the sub-processes stdout, which allows interacting with the sub-process at a low level.

Methods

close(): void

Clean up resources associated with the sub-process instance.

kill(signo?: Signal): void

Send a signal to process. Default signal is "SIGTERM".

const p = Deno.run({ cmd: [ "sleep", "20" ]});
p.kill("SIGTERM");
p.close();
output(): Promise<Uint8Array>

Buffer the stdout until EOF and return it as Uint8Array.

You must set stdout to "piped" when creating the process.

This calls close() on stdout after its done.

status(): Promise<ProcessStatus>

Wait for the process to exit and return its exit status.

Calling this function multiple times will return the same status.

The stdin reference to the process will be closed before waiting to avoid a deadlock.

If stdout and/or stderr were set to "piped", they must be closed manually before the process can exit.

To run process to completion and collect output from both stdout and stderr use:

const p = Deno.run({ cmd: [ "echo", "hello world" ], stderr: 'piped', stdout: 'piped' });
const [status, stdout, stderr] = await Promise.all([
  p.status(),
  p.output(),
  p.stderrOutput()
]);
p.close();
stderrOutput(): Promise<Uint8Array>

Buffer the stderr until EOF and return it as Uint8Array.

You must set stderr to "piped" when creating the process.

This calls close() on stderr after its done.