Returns a specified number of characters from an input stream.
object.Read(characters) |
Arguments
- object
-
StdIn text stream object.
- characters
-
Integer value indicating the number of characters you want to read.
Remarks
The Read method returns a string. The StdIn, StdOut, and StdErr properties and methods work when running the script with the CScript.exe host executable file only. An error is returned when run with WScript.exe. Reading begins at the current position pointer location and moves forward one character at a time.
The Read method does not return until the enter key is pressed. Only the number of characters requested will be returned. Any additional characters will be returned on subsequent calls to the Read, ReadLine, or ReadAll methods.
Example
The following code uses the Read method to get a character from the keyboard and display it on the console.
Visual Basic Script | Copy Code |
---|---|
Dim Input Input = "" Do While Not WScript.StdIn.AtEndOfLine Input = Input & WScript.StdIn.Read(1) Loop WScript.Echo Input |
JScript | Copy Code |
---|---|
var input = ""; while (!WScript.StdIn.AtEndOfLine) { input += WScript.StdIn.Read(1); } WScript.Echo(input); |