Kdb+ communicates with the system (console, stdout, stderr), file system, and other processes through connection handles.
There are three permanent system handles:
0 console 1 stdout 2 stderr
A handle is an int atom but is variadic. Syntactically, it can be an int atom or a unary function.
q)1 / one is one 1 q)1["abc\n"] / or stdout abc 1
A handle is an applicable value. It (and its negation) can be applied to an argument and iterated.
Write to a handle
Applied to an argument, a handle writes the argument to its target and returns itself.
stdout and stderr
q)a:1 "quick brown fox\n" quick brown fox q)a 1
Write only chars to stdout and stderr.
q)1[200 300] 'type  1[200 300] ^
Negate the handle to append a newline to the string.
q)1 "lazy dog" lazy dog1 q)-1 "lazy dog" lazy dog -1
q)0 "1 \"hello\"" /string hello1 q)0 (+;2;2) /parse tree 4
Reading from the console with
read0 permits interactive input.
q)\ls data ls: data: No such file or directory 'os  \ls data ^ q)h:hopen `:data/new q)h /handle is an integer 3i q)type h /atom -6h q)h "now is the time" /but can be applied as a unary 3i q)/and iterated q)h each (" for all good men";" to come to the aid of the party") 3 3i q)hclose h q)read0 `:data/new /hopen created file path "now is the time for all good men to come to the aid of the party"