mattvr
mattvr
DDeno
Created by mattvr on 3/24/2024 in #help
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);
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);
3 replies
DDeno
Created by mattvr on 4/14/2023 in #help
How to re-open Deno.stdin?
I'm noticing that Deno gives an error when trying to window.prompt after I've consumed stdin.
// prompt.ts
// echo "test" | deno run prompt.ts

let message = ''
const decoder = new TextDecoder();

for await (const chunk of Deno.stdin.readable) {
const textChunk = decoder.decode(chunk);
message += textChunk
}

console.log('got', message)

window.prompt('hello?')
// prompt.ts
// echo "test" | deno run prompt.ts

let message = ''
const decoder = new TextDecoder();

for await (const chunk of Deno.stdin.readable) {
const textChunk = decoder.decode(chunk);
message += textChunk
}

console.log('got', message)

window.prompt('hello?')
When invoked:
> echo "test" | deno run prompt.ts
got test

error: Uncaught (in promise) BadResource: Bad resource ID
window.prompt('hello?')
^
at isatty (ext:runtime/40_tty.js:19:7)
at prompt (ext:runtime/41_prompt.js:36:8)
at [..]/prompt.ts:14:8
> echo "test" | deno run prompt.ts
got test

error: Uncaught (in promise) BadResource: Bad resource ID
window.prompt('hello?')
^
at isatty (ext:runtime/40_tty.js:19:7)
at prompt (ext:runtime/41_prompt.js:36:8)
at [..]/prompt.ts:14:8
Is it not possible to re-open Deno.stdin for reading more than once? I notice it's closed from Deno.resources after the initial read. I'm doing this for a command line utility which supports I/O piping. Thanks for any help!
1 replies
DDeno
Created by mattvr on 4/12/2023 in #help
deno.land/x/module not using latest tag
I created a repository, at deno.land/x/shellgpt, and pushed some tags. The latest version is v0.2.0. When I do deno install -A --name gpt https://deno.land/x/shellgpt/mod.ts I'd expect it to resolve to the latest, v0.2.0, but it's unexpectedly installing an older/broken version, v0.1. This seems to be a bug in deno.land or I'm doing something wrong. I had deleted some of these earlier tags and maybe the repo is in a bugged state?
5 replies