How do I end a remote KDB + session via a script?
I need to kill a remote KDB + session. There are several ways to do this, but I would rather use IPC handlers.
I start a KDB + session:
$ q -p 5000
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems
Then I start another KDB session and I manage to successfully shutdown the server:
$ q
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems
q)h: hopen `::5000
q)h(exit;0)
'close
q)\\
But if I create a script (test.q) with the above instructions, it doesn't work:
$ cat test.q
h: hopen `::5000
h(exit;0)
\\
$ q test.q
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems
k){0N!x y}
'close
@
"q"
"h(exit;0)"
q))
Any ideas? I appreciate it very much.
source to share
You are making a synchronous request to the remote server, which means that you are waiting for a response. The problem is that your request causes the remote server to immediately disconnect and immediately close the connection, which results in an error and causes q to go into debug mode.
If you just want to send the output to the remote server without an error, you can send the request asynchronously using a negative value for the connection descriptor (note that there is no "close error"):
q)h: hopen `::5000
q)(neg h) (exit;0)
q)\\
source to share
I managed to figure it out using Protected Evaluation :
In the test.q file :
h: hopen `::5000
@[h; "exit 0"; {}]
\\
source to share