class Deno.Command
Unstable

Create a child process.

If any stdio options are not set to "piped", accessing the corresponding field on the Command or its CommandOutput will throw a TypeError.

If stdin is set to "piped", the stdin WritableStream needs to be closed manually.

const command = new Deno.Command(Deno.execPath(), {
  args: [
    "eval",
    "console.log('Hello World')",
  ],
  stdin: "piped",
});
command.spawn();

// open a file and pipe the subprocess output to it.
command.stdout.pipeTo(Deno.openSync("output").writable);

// manually close stdin
command.stdin.close();
const status = await command.status;
const command = new Deno.Command(Deno.execPath(), {
  args: [
    "eval",
    "console.log('hello'); console.error('world')",
  ],
});
const { code, stdout, stderr } = await command.output();
console.assert(code === 0);
console.assert("hello\n" === new TextDecoder().decode(stdout));
console.assert("world\n" === new TextDecoder().decode(stderr));
const command = new Deno.Command(Deno.execPath(), {
  args: [
    "eval",
    "console.log('hello'); console.error('world')",
  ],
});
const { code, stdout, stderr } = command.outputSync();
console.assert(code === 0);
console.assert("hello\n" === new TextDecoder().decode(stdout));
console.assert("world\n" === new TextDecoder().decode(stderr));

Constructors

new
Command(command: string | URL, options?: CommandOptions)

Properties

readonly
pid: number
readonly
status: Promise<CommandStatus>

Get the status of the child process.

readonly
stderr: ReadableStream<Uint8Array>
readonly
stdin: WritableStream<Uint8Array>
readonly
stdout: ReadableStream<Uint8Array>

Methods

kill(signo?: Signal): void

Kills the process with given Deno.Signal. Defaults to "SIGTERM".

output(): Promise<CommandOutput>

Executes the Deno.Command, waiting for it to finish and collecting all of its output. If spawn() was called, calling this function will collect the remaining output.

Will throw an error if stdin: "piped" is set.

If options stdout or stderr are not set to "piped", accessing the corresponding field on Deno.CommandOutput will throw a TypeError.

Synchronously executes the Deno.Command, waiting for it to finish and collecting all of its output.

Will throw an error if stdin: "piped" is set.

If options stdout or stderr are not set to "piped", accessing the corresponding field on Deno.CommandOutput will throw a TypeError.

ref(): void

Ensure that the status of the child process prevents the Deno process from exiting.

spawn(): void

Spawns a streamable subprocess, allowing to use the other methods.

unref(): void

Ensure that the status of the child process does not block the Deno process from exiting.