简体   繁体   中英

RingoJS javascript - get user input on console

When using Rhino or RingoJS, one can use print on the console REPL to print output ( alert is not available).

What can be used to read user input on the console, instead of prompt ?

Is there somewhere I can find information on these conventions, what APIs are available in Rhino and/or RingoJS, or is there a CommonJS guide they are adhering to?

The short answer is that currently there is no standard (widely supported) way of reading bytes from the standard input stream. With Rhino you could simply use the Java "System.in" input stream; RingoJS does apparently implement the System module .

It looks like the CommonJS group is still working on a draft of the "System" specification which includes a "stdin" object which should be an input stream and behave just like a file opened in "r" mode; such an object should also include a " read() " method. Note however that these are all draft specs and it looks like very few JavaScript environments provide implementations. In an environment which does implement the System and IO specs you should be able to do something like this:

var system = require('system');
system.stdin.read(10); // Read ten bytes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM