Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/proc/tools/deps/proc.ts>Process

A better way to work with processes in Deno.
Go to Latest
class Process
implements [Deno.Closer]
Re-export
import { Process } from "https://deno.land/x/proc@0.20.34/tools/deps/proc.ts";

A wrapper for Deno.ChildProcess that converts streams to AsyncIterable<...>, corrects error handling, and adds other custom stuff.

This is used as the basis for the run methods in this library. This can be used standalone but is more difficult to work with.

Constructors

new
Process(
cmd: string | URL,
args: readonly string[],
)

Constructor.

Properties

private
_isClosed: boolean
private
_passError: Error | undefined
private
_stderr: AsyncIterable<Uint8Array> | undefined
private
_stdin: WritableIterable<
| Uint8Array
| Uint8Array[]
| string
| string[]
> | undefined
private
_stdout: AsyncIterable<Uint8Array> | undefined
private
stderrResult: Promise<S> | undefined
protected
readonly
process: Deno.ChildProcess

The wrapped process.

readonly
isClosed: boolean

Indicates close has been called.

readonly
pid

Process PID.

readonly
status

Process status.

readonly
stderr: AsyncIterable<Uint8Array>

stderr of the process.

readonly
stdin: Writable<
| Uint8Array
| Uint8Array[]
| string
| string[]
>

stdin as a WritableIterable.

This property is here to make the interface philosophically compatible with stdin of the wrapped process, but uses a mechanism that JavaScript does not optimize very well. Recommend using writeToStdin instead if that is possible.

readonly
stdout: AsyncIterable<Uint8Array>

stdout of the process.

Methods

close(): Promise<void>

Do all necessary normal steps to close the process. This does not kill the process but attempts a normal close.

writeToStdin(iter: AsyncIterable<
| Uint8Array
| Uint8Array[]
| string
| string[]
>
): Promise<void>

This is the "backdoor" way to write directly to the underlying process stdin without the overhead of a WritableIterable. Use instead of stdin for streamed data.

stdin is the way to go if you are passing ad-hoc, non-continuous data to process stdin. However, it adds a substantial amount of overhead, and it is very slow for processing small data. Using this function instead of stdin greatly improves performance where small data is a factor.