From Kx Wiki
Jump to: navigation, search


Running q as a service on Windows

SrvAny is a tool found in the Windows NT Resource Kit that is used for running Windows NT applications as services. You can download it from Microsoft site:[1] .

To create a Windows NT user-defined service, perform the following steps: 1.Copy srvany.exe to c:\q 2. At command prompt(cmd.exe), type

instsrv.exe q5010 c:\q\srvany.exe

This will create service named q5010. We will use it to run q on port 5010(tickerplant)

3.Prepare Windows registry file to setup parameters for q5010 service:

Windows Registry Editor Version 5.00

"AppParameters"="-p 5010 -q"

4. Now you can use q5010 service as usual windows service:

To start:

sc start q5010
net start q5010

To stop:

sc stop q5010
net stop q5010

If you want setup several instances repeat steps 2-3 for different service names and ports. If you run tickerplant, realtime and historical database you will have 3 services at minimum, q5010, q5011, q5012. To start in appropriate order you can setup dependencies between q5011 and q5010

sc.exe q5011 depend= q5010

Note that sign '=' must be immediately after word depend and space before service name.

In this way you can setup on windows complete kdb setup that starts and stops in right way.

Additional features:

Output redirect:

Also if you need to do redirect of output you must modify application using following reg file.

Windows Registry Editor Version 5.00

"AppParameters"="/c c:\\q\\w32\\q.exe -p 5010 -q >c:\\q\\logs\\q.5010.log"

I've experienced some problems with redirecting output, so it would be great if someone can update article to fix this.

Environment setup:

1.Start regedit and go to following subkey:


2. Add Value with name AppEnvironment with type REG_MULTI_SZ

3. In the Multi-String Editor, enter environment variables using the syntax <variable name>=<value>.


Do not forget to add a new line after the last line, or the value will be ignored.

Related articles:

How To Create a User-Defined Service

Troubleshooting SrvAny Using Cmd.exe

Passing Environment Variables to Applications Started by SRVANY

You receive an "An operation was attempted on something that is not a socket" error message when you try to connect to a network

Personal tools