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.

+4


source to share


4 answers


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)\\

      

+5


source


I managed to figure it out using Protected Evaluation :

In the test.q file :



h: hopen `::5000
@[h; "exit 0"; {}]
\\

      

+2


source


You can try asynchronous. Also, if necessary, you can try to defer async (neg h) ({exit 0}; ') []

0


source


You have the option to explicitly close the session and discard the handle:

h: hopen ':hostname:port  <BR>
h <BR>
h:hclose <BR>
h<BR>

      

0


source







All Articles