I am completely reworking this API. What is here works, mostly. It’s useful. The new API will address the issues I found while creating this one. It is a lot more ambitious in scope. I will release something as soon as it feels like it is starting to gel. Checkout feature branch 9 for progress.

deno-proc

Abstractions for running processes in Deno.

This is still very early. Things are going to change. A lot. Functionality is limited. The API is unstable.

Deno has all the right parts for working with processes, but I really want something that is a better version of what I get in bash scripts. I want stdin and stdout pipes, decent default error handling, and minimal need to manually close things. I want all this to work with a fluent API.

documentation

deno doc -q https://deno.land/x/proc/mod.ts

stdout from a process as lines

for await (const line of run({ cmd: ["ls", "-la"] }).stdoutLines()) {
  console.log(line);
}

pipe stdout to stdin

const fileCount = await first(
  run({ cmd: ["ls", "-1"] })
    .pipe(run({ cmd: ["wc", "-l"] }))
    .stdoutLines(),
);

console.info(
  `Total number of files and folders in <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>o</mi><mi>l</mi><mi>v</mi><mi>e</mi><mo stretchy="false">(</mo><mi mathvariant="normal">&quot;</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">&quot;</mi><mo stretchy="false">)</mo></mrow><mi>i</mi><mi>s</mi></mrow><annotation encoding="application/x-tex">{resolve(&quot;.&quot;)} is </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal">reso</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">e</span><span class="mopen">(</span><span class="mord">&quot;.&quot;</span><span class="mclose">)</span></span><span class="mord mathnormal">i</span><span class="mord mathnormal">s</span></span></span></span>{
    parseInt(fileCount!, 10)
  }.`,
);

process stderr lines

I’ve implemented .stderrLines() to allow access to the standard error stream. To gain access to this, you have to pass in pipeStderr: true when you create the process.

I don’t like this need for a-priori knowledge, and use of this is still more awkward than I would like. I am putting it in because it solves the problem, but expect API changes around this.