mattvrM
Denoβ€’3y ago
mattvr

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?')


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


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!
Was this page helpful?