How to write "zwrite" output to $$$TRACE?
SET ^||fruit(1)="apple",^||fruit(4)="banana",^||fruit(8)="cherry"
SET ^||fruit(1,1)="Macintosh",^||fruit(1,2)="Delicious",^||fruit(1,3)="Granny Smith"
SET ^||fruit(1,2,1)="Red Delicious",^||fruit(1,2,2)="Golden Delicious"
SET ^||fruit="Fruits"
ZWRITE ^||fruit
^||fruit="Fruits"
^||fruit(1)="apple"
^||fruit(1,1)="Macintosh"
^||fruit(1,2)="Delicious"
^||fruit(1,2,1)="Red Delicious"
^||fruit(1,2,2)="Golden Delicious"
^||fruit(1,3)="Granny Smith"
^||fruit(4)="banana"
^||fruit(8)="cherry"
How I do send the output of zwrite to $$$TRACE()?
Product version: IRIS 2021.2
use the redirect package from Open Exchange to write it to string
https://openexchange.intersystems.com/package/IO-Redirect
s myf = tmpFile.Filename = ##class(%File).TempFilename("txt")
open myf:("NW") USE myf ZWRITE ^||fruit
CLOSE myf
s tLine = ""
d tmpFile.Rewind()
while ('tmpFile.AtEnd) {
set tLine = tLine_tmpFile.ReadLine()
}
d ##class(%File).Delete(myf)
w tLine
I'm quite shure, the above code won't work as expected, or with the words of Joseph Weizenbaum: “A computer will do what you tell it to do, but that may be much different from what you had in mind.”
The content of your myf variable is always 0 (the result of comparing nullstring with a filename), the size of tmpFile stream is also 0 (you never write into the stream).
Sometimes it's faster to write a "oneliner" to solve a simple problem then searching and downloading a solution from openexchange or from whereever... That's the beauty of the ObjectScript.
And if you think, the oneliner is worth to be reused, then make it to a method, add some small adjustments for a general usability...
The oneliner
The more general version
Use it as
You could redirect output to anything convenient (spool device, interprocess communication device, host file) then read it back into a variable and $$$TRACE the variable. E.g., a two-liner using spool device 1: