Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see Why Migrate to InterSystems IRIS?

Read Command

Read allows you to prompt the user for information, and store the user's response temporarily in a variable. You can use Write to display the contents of the variable. We'll cover variables in depth a little later. Variables are case-sensitive. In this tutorial, the user's responses to Read are CAPITALIZED.

SAMPLES>read x
BEST FRIEND
SAMPLES>write "You just typed: ", x
You just typed: BEST FRIEND
SAMPLES>

Since it allows prompting, Read shares some functionality with Write. You can wait for a user to respond indefinitely, or you can specify a timeout: how long (in seconds) to wait. If the user presses Enter without entering any characters, the variable will contain the zero-length (empty) string.

You can wait for any number of characters, or you can specify a maximum length. In this case, the user may enter fewer characters than you specify, pressing Enter when finished. Or, if the user enters the maximum number of characters, Read terminates automatically.

SAMPLES>read ?30, "Enter your name: ", n
                              Enter your name: ALEXANDER
SAMPLES>read !, "You have 5 seconds to respond: ", x:5

You have 5 seconds to respond: I TYPED THIS IN 5 SECONDS
SAMPLES>read !, "Type 5 characters and don't press Enter: ", z#5

Type 5 characters and don't press Enter: ABCDE
SAMPLES>
Feedback