Running a Process
proc
lets you run a process from Deno with as little boilerplate as possible.
import { run } from "https://deno.land/x/proc@0.22.1/mod.ts";
To ls -la
:
await run("ls", "-la").toStdout();
To capture the lines as an array:
const lines: string[] = await run("ls", "-la").lines.collect();
Create a Command Programmatically
import { Cmd, run } from "https://deno.land/x/proc@0.22.1/mod.ts";
A command requires that the first parameter be defined, and that it be either a
string or a URL. Additional parameters are string values. This doesn't quite fit
the signature of an array. Use
Cmd as the type of the array.
This can be spread into run
.
// Assume options.all is a defined boolean.
const cmd: Cmd = ["ls"];
if (options.all) {
ls.push("-la");
}
await run(...cmd).toStdout();
The command array is type Cmd
, not string[]
. You need to declare this
explicitly.