You can also redirect standard input, standard output, and standard error devices to a file. You could use redirection in the following program, but you would first need to issue two SET DD: statements to allow the redirection to work. They are:
set dd:sysprint=stdout:
set dd:sysin=stdin:
Hello: proc options(main);
put list('Hello!');
end;
After compiling and linking the program, you could invoke it from the command line by entering:
hello2 > hello > hello2.out
As is true with display statements, the greater than sign redirects the output to the file that is specified after it, in this case HELLO2.OUT. This means that the word 'HELLO' is written in the file HELLO2.OUT. Note also that the output includes printer control characters since the PRINT attribute is applied to SYSPRINT by default.
READ statements can access data from stdin, however, they must specify an LRECL equal to 1.