Subprocesses: Collecting output

We don't often write programs in isolation. In a lot of cases we want to interact with the outside system and spawning a subprocess is a common way to do this.

const command = new Deno.Command("deno", {
  args: [
    "eval",
    "\
    console.log('hello from deno'); \
    console.error('hello from stderr'); \
    ",
  ],
});
let result = await command.output();
result = command.outputSync();
const textDecoder = new TextDecoder();
console.log("stdout:", textDecoder.decode(result.stdout));
console.log("stderr:", textDecoder.decode(result.stderr));

Run this example locally using the Deno CLI:

deno run --allow-run https://docs.deno.com/examples/scripts/subprocesses_output.ts

Did you find what you needed?