Skip to content

How to read an int from stdin? #15872

Answered by ayame113
lifubang asked this question in Q&A
Sep 12, 2022 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

I'm not sure if I understand the problem correctly, but what about something like this?

const reader = Deno.stdin.readable.pipeThrough(new TextDecoderStream());
for await (const chunk of reader) {
  console.log(Number(chunk));
}
> deno run readInt.ts
123
123
456
456

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@lifubang
Comment options

@lifubang
Comment options

@lifubang
Comment options

@ayame113
Comment options

Answer selected by lifubang
Comment options

You must be logged in to vote
1 reply
@0f-0b
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants