mattvrM
Deno2y ago
2 replies
mattvr

Read child process I/O

I want to write a simple Deno CLI script using Deno.Command or dx that can read output from a shell utility.

For example, gum input --placeholder=\"Enter your name\" displays a small text input, which I want to read the user input into Deno.

- If I use a Deno.Command stdout: "inherit", then Deno doesn't have access to the stdout stream (containing the user name), just the file signal.
- So I tried stdout: "piped" and piping the streams – but then the terminal hangs and displays nothing.

Does this use look right?:
const cmd = new Deno.Command("gum", {
  args: [
    "input",
    "--placeholder=\"Enter your name\"",
  ],
  stdin: "piped",
  stdout: "piped",
  stderr: "piped",
})
const process = cmd.spawn()
Deno.stdin.readable.pipeTo(process.stdin);
process.stdout.pipeTo(Deno.stdout.writable);
process.stderr.pipeTo(Deno.stderr.writable);
Was this page helpful?