Null devices comprise of a collection of system purpose devices that include /dev/null, /dev/zero, /dev/random, and /dev/urandom.
/dev/null returns a null string on READ and sets $ZEOF
/dev/random and /dev/urandom return a random value on READ and set $ZEOF
/dev/zero returns 0's on READ and does not set $ZEOF
A null device discards all output. GT.M maintains a virtual cursor position for null devices as it does for terminals on output. Use null devices for program testing and debugging, or for jobs that permit I/O to be discarded under certain circumstances. For example, JOB processes must have input and output devices associated with them, even though they do not use them. Null devices are low overhead never-fail alternatives for certain classes of I/O.
The following table provides a brief summary of deviceparameters for null devices. For more detailed information, refer to “Open”, “Use”, and “Close”.
Null Deviceparameters | ||
---|---|---|
DEVICEPARAMETER |
COMMAND |
COMMENT |
O: Applies to the OPEN command U: Applies to the USE command C: Applies to the CLOSE command | ||
EXCEPTION=expr |
O/U/C |
Controls device-specified error handling. For the null device this is only EOF handling and therefore exceptions can never be invoked except by a READ. |
[NO]FILTER[=expr] |
U |
Controls some $X,$Y maintenance. |
[Z]LENGTH=intexpr |
U |
Controls the length of the virtual page. |
[Z]WIDTH=intexpr |
U |
Controls maximum size of a record. |
[Z][NO]WRAP |
O/U |
Controls handling of records longer than the maximum width. |
X=intexpr |
U |
Sets $X to intexpr. |
Y=intexpr |
U |
Sets $Y to intexpr. |
This section contains examples of null device usage.
Example:
GTM>do ^runrep runrep; zprint ^runrep set dev="/dev/null" set hdr="********* REPORT HEADER ************" open dev use dev set x="" write hdr,!,$zdate($horolog),?30,$job,! for set x=$order(^tmp($job,x)) quit:x="" do REPORT quit REPORT; ;large amount of code quit;
This program produces a report derived from the information in the global variable ^tmp. The unspecified routine REPORT may potentially contain a large amount of code. To see that the basic program functions without error, the programmer may discard the output involved in favor of watching the function. To run the program normally, the programmer simply has to change the variable dev to name another device and the routine REPORT writes to the dev device.
Example:
job ^X:(in="/dev/null":out="/dev/null":err="error.log") JOB ^X:(IN="/dev/null":OUT="/dev/null":ERR="error.log")
This example issues a GT.M JOB command to execute the routine ^X in another process. This routine processes a large number of global variables and produces no output. In the example, the JOBbed process takes its input from a null device, and sends its output to a null device. If the JOBbed process encounters an error, it directs the error message to error.log.