Service Automation
The SPACE GASS API runs as a local HTTP service launched from the SpaceGassApi executable installed with SPACE GASS. For interactive use you can double-click the shortcut and leave it running, but for scripts and batch jobs you usually want your code to manage the service itself — start it on demand, wait until it is ready, run your work, and shut it down cleanly when done.
The SDK does not ship a service-lifecycle helper. The pattern is short enough to keep in your own project; the boilerplate below is a copy-paste starting point for both C# and Python.
The Lifecycle
A typical script does four things:
- Probe — try
Service.Infoto see if the service is already running. If yes, reuse it (don't kill someone else's instance). - Start — if not running, launch
SpaceGassApi.exeas a child process. - Wait — poll
Service.Infountil it responds, or fail with a timeout if the service never comes up. - Stop — when your script is finished, terminate the child process if (and only if) you started it. Skip cleanup if the service was already running before your script ran.
Wrap steps 2–4 in a try / finally (C#) or context manager (Python)
so the service still shuts down if your code throws.
Boilerplate
The example below probes for an existing service, starts one if
needed, waits up to 30 seconds for it to become ready, fetches
Service.Info to confirm, then shuts the service down.
Custom Ports
To run the service on a non-default port — useful if 34560 is in use,
or if you want to run multiple instances side by side — pass --port
to the executable and the matching base URL to CreateClient:
Handling Ctrl+C
The try / finally (C#) and context manager (Python) above handle
exceptions correctly, but a hard interrupt (Ctrl+C) skips them by
default. Wire a signal handler so the service still shuts down on
abort:
Tips
- Locate the executable — the install path varies by SPACE GASS
version. Read it from configuration or an environment variable
rather than hard-coding
C:\Program Files\SPACE GASS 14.5\so the same script keeps working after an upgrade. - One service at a time on the default port — if
34560is already bound (perhaps by an interactive instance the user launched), starting another on the same port will fail. Either pick a different port or accept the existing one (the boilerplate above does the latter). - Don't kill a service you didn't start — the
finallyblock guards onserviceProcess != null, so a script that found an already-running service leaves it running. Useful when developing interactively in the same session as a long-lived service. - Surface service stdout — for debugging, redirect the child
process's
StandardOutput/StandardErrorto a log file. The boilerplate usesCreateNoWindow = trueso the service runs invisibly; flip that off (or omit it) if you want the console to show service messages.
Run this example locally
The complete program with error handling and Ctrl+C wiring is in the
repo as
Example.ServiceAutomation (C#) and
service_automation (Python).
Clone the repo and run it directly — no copy-paste:
Edit the ServiceExePath / SERVICE_EXE constant first to match the
SPACE GASS install path on your machine.

