-8! returns the IPC byte representation.
On disk the binary format is different. To read this data use get.
To stream data to a log file you need to create the empty file first
https://code.kx.com/q/kb/replay-log/#replaying-log-files
q)`:out set () /This important part adds a header to the file to set the type
`:out
q)h:hopen `:out
q)h (1 2;3)
600i
q)hclose h
q)get `:out
1 2
3
Note if you wish to write your item as a single element to the list then use enlist
q)`:out set ()
`:out
q)h:hopen `:out
q)h enlist (1 2;3)
616i
q)hclose h
q)get `:out
1 2 3
Binary and text data can also be written to a file which is what you are doing.
https://code.kx.com/q/ref/hopen/#files
The intention is to write specific pieces of data
q)h 0x2324 /Write some binary
q)h "some text\n" /Write some text
In your code the binary representation of the raw KX object does get written but no header is added (it is neither IPC nor disk format). So when you read back the data it cannot be interpreted correctly by either -9!
or get
.
Valid file binary created with `:out set ()
has a file header:
(Can be read by get
)
q)read1 `:out
0xff0100000000000000000200000007000200000001000000000000000200000000000000f90300000000000000
Valid IPC binary with IPC header:
(Can be read by -9!)
q)-8!(1 2;3)
0x010000002d00000000000200000007000200000001000000000000000200000000000000f90300000000000000
Your raw object in binary - no header present to enable interpretation
q)read1 `:out
0x07000200000001000000000000000200000000000000f90300000000000000