\[1|2] filename
\1 and \2 let you redirect stdout and stderr to files from within the q session. The files
and intermediate directories are created if necessary.
~/q$ rm -f t1.txt t2.txt
~/q$ l64/q
KDB+ 2.6 2010.05.10 Copyright (C) 1993-2010 Kx Systems
...
q)\1 t1.txt / stdout
q)\2 t2.txt / stderr
til 10
2 + "hello"
\\
~/q$ cat t1.txt / entry in stdout
0 1 2 3 4 5 6 7 8 9
~/q$ cat t2.txt / entry in stderr
q)q)'type
On macOS and Linux \1 /dev/stdin returns output to the default.