As OS/2 starts an application, it automatically opens the three standard files and makes the file handles-numbered 0, 1, and 2-available to the application. Applications can read from and write to the standard files as soon as they start.
Standard Input
File handle 0 is the standard input file. This handle can be used to read
characters from the keyboard with DosRead.
The function reads the specified number of characters unless the user types
a turnaround character-that is, a character that marks the end of
a line (the default turnaround character is a carriage-return/linefeed character
pair).
As DosRead reads the characters, it copies them to the buffer you have supplied, as shown in the code fragment below.
In this example, DosRead copies the number of characters read from standard input to to variable cbRead. DosRead also copies the turnaround character, or characters, to the buffer If the function reads fewer than 80 characters, the turnaround character is the last one in the buffer.
Standard Output
File handle 1 is the standard output file. This handle can be used to write
characters on the screen with DosWrite.
The function writes the characters in the given buffer to the current line.
If you want to start a new line, you must place the current turnaround character
in the buffer.
The code fragment below:
#define INCL_DOSFILEMGR /* File system values */ #include <os2.h> #define HF_STDIN 0 /* Standard input handle */ #define HF_STDOUT 1 /* Standard output handle */ #define BUF_SIZE 80 ULONG ulWritten, ulRead; BYTE abBuffer[BUF_SIZE]; static UCHAR ucEnterName[] = "Enter a name: "; DosWrite(HF_STDOUT, ucEnterName, sizeof(ucEnterName), &ulWritten); DosRead(HF_STDIN, abBuffer, sizeof(abBuffer), &ulRead); DosWrite(HF_STDOUT, abBuffer, ulRead, &ulWritten);
Standard Error
File handle 2 is the standard error file. This handle, like the standard
output handle, enables applications to write characters on the screen. Most
applications use the standard error file to display error messages, enabling
the application to redirect standard output to a file without also redirecting
error messages to the file.