Next: Adding project templates, Previous: Adding support for new Version Control Systems, Up: Customizing and Extending GPS
In order to give access to the GPS capabilities from external processes
(e.g. Emacs
), GPS can be launched in server mode.
The two relevant command line switches are --server
and
--hide
.
--server
will open a socket on the given port, allowing multiple
clients to connect to a running GPS, and sending GPS shell or python
commands.
--hide
tells GPS not to display its main window when starting.
note that under unix systems, you still need to have access to the current
screen (as determined by the DISPLAY
environment variable) in this
mode.
Using the two switches together provides a way to launch GPS as a background process with no initial user interface.
Clients connecting through a standard socket have access to a simple
shell using GPS>>
as the separating prompt between each command. This
is needed in order to determine when the output (result) of a command
is terminated.
All the GPS shell commands (as defined in The GPS Shell) are
available from this shell. In addition, the python interpreter, if
enabled, is also available through the use of the python
prefix
before a python command.
For example, sending pwd
through the socket will send the pwd
command through the GPS shell and display the result on the socket;
similarly, sending python GPS.pwd()
will send the GPS.help()
command through the python interpreter (see The Python Interpreter for
more details).
The socket shell provides also additional commands:
For example, let suppose that we start gps with the --server=1234
command: this will bring up GPS as usual.
Now, on a separate terminal, create a simple client by typing the following:
telnet localhost 1234 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPS>> id test-1 id set to 'test-1' GPS>> pwd c:\working-dir\ GPS>>
Then in the GPS Python Console:
>>> GPS.Socket ("test-1").send ("hello, it's time to logout\n");
At this point, the following is received on the client (telnet) side:
GPS>> hello, it's time to logout
We can then close the client:
logout Connection closed by foreign host.