从Deno stdin获取价值 [英] Getting values from Deno stdin
本文介绍了从Deno stdin获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题很简短,我们如何从标准输入中获取值?
My question is really short, How can we get values from standard input ?
我不知道如何使用Deno.stdin
吗?
一个例子,将不胜感激.
An example would be appreciated.
谢谢
推荐答案
Deno.stdin
is of type File
, thus you can read from it by providing a Uint8Array
as buffer and call Deno.stdin.read(buf)
window.onload = async function main() {
const buf = new Uint8Array(1024);
/* Reading into `buf` from start.
* buf.subarray(0, n) is the read result.
* If n is instead Deno.EOF, then it means that stdin is closed.
*/
const n = await Deno.stdin.read(buf);
if (n == Deno.EOF) {
console.log("Standard input closed")
} else {
console.log("READ:", new TextDecoder().decode(buf.subarray(0, n)));
}
}
这篇关于从Deno stdin获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文