SPOOL - the forgotten device
In recent discussions, answers, comments IO redirection (with the famous code) was quite often seen
as the ultimate solution. It is definitely strong stuff and you can not only log your output but also do
key-grabbing in input.
But I think for simple logging it's quite a significant overhead.
If you just need to get some text or dump your variables or objects then SPOOL should be sufficient for your needs.
The principle goes back to the roots and some utilities as
^%IS,^%SPOOL,%SPL* written in quite ancient style
are more interesting for programming archeology than really useful.
Online documentation on SPOOL is complete and tells you almost all details.
For daily use you should know
- Device = 2
- it has an integer documentId (default=1)
- it has an integer lineNumber (default =1)
You start it by OPEN 2:documentId USE 2 and your redirection is done.
All further WRITES now end up in Global
and when you are finished or your job dies CLOSE 2 completes the redirection.
Or you return to your primary device by USE $P and keep the spool open for other output.
If you want to append to an existing document you have to get next line to write as start for the OPEN
OPEN 2(documentId:append) USE 2
The SPOOL DEVICE ignores any READ and returns ""
So the easiest de-spooling - just lists the global:
FOR i=1:1 QUIT:'$DATA(^SPOOL(documentId,i),val) WRITE val
Find attached a small summary of all you need to use SPOOL for debugging:
This is a coding example working on Caché 2018.1.3 and IRIS 2020.2 It will not be kept in synch with new versions It is also NOT serviced by InterSystems Support !