Scripts using the Scripting API can be run from the command line without a Pulsonix graphical user interface.
Running Pulsonix without an interface
In a command prompt, Pulsonix can be passed several different flags when launched to change the behaviour of the
application. One of these flags is -hidden, which makes the application launch and run without a
graphical user interface. This also decreases Pulsonix start-up time.
To run Pulsonix invisibly, navigate to the folder containing Pulsonix.exe and open a command prompt, then use the
command pulsonix.exe -hidden. The application will not be closed until the associated command prompt
is closed.
Scripting API
The Scripting API is available if:
- The scripting server has been started in the Scripting Dashboard or configured to automatically start.
- An instance of Pulsonix is running on the computer, either with a graphical interface (as it normally would be), or in “hidden” mode described above.
To run a script which uses the Scripting API, you must first run Pulsonix and then proceed with API calls. Running Pulsonix can be done as part of a secondary batch script or within the script itself.
Below is an example of a script using the Pulsonix Python client which automatically opens Pulsonix if necessary. Any Python script can be invoked from the command line.
import psutil, subprocess, time, win32pipe, pywintypes, pulsonix
PULSONIX_PATH = None # E.g. r"C:\ProgramFiles\Pulsonix 14.0\Pulsonix.exe"
DETACHED_PROCESS = 0x00000008
CREATE_NEW_PROCESS_GROUP = 0x00000200
def is_process_running(process_name):
for process in psutil.process_iter(['name']):
if process.info['name'] == process_name:
return True
return False
def wait_for_pipe():
for i in range(10):
try:
# Always throws if the pipe isn't available
win32pipe.WaitNamedPipe(pulsonix.psxutils.PIPE_PATH, 1000)
return True
except pywintypes.error as e:
if e.winerror != 2: # 2 == FILE_NOT_FOUND
raise # Unexpected: re-raise
time.sleep(1)
return False
def ensure_pulsonix_is_running():
if PULSONIX_PATH is None:
print("Please provide the location of Pulsonix.exe in PULSONIX_PATH.")
quit(1)
if is_process_running("Pulsonix.exe"):
print("Pulsonix is already running.")
return True
subprocess.Popen([PULSONIX_PATH, "-hidden"])
return wait_for_pipe()
if not ensure_pulsonix_is_running():
print("Failed to ensure Pulsonix is running...")
quit(1)
print(f"Pulsonix version: {pulsonix.GetVersion()}")
pulsonix.QuitApp()
Related Topics
Scripting Overview | Running Python scripts | Getting started with Python scripting | Python scripting FAQ