Recent versions of IRIS come with Lite Terminal available from VSCode. It's a websocket server, with JSON messaging. Here's how to connect to it from Python:
import websocket
import argparse
import requests
import json
def terminal(host, port, namespace, username, password, command, secure):
session = requests.Session()
r = session.get(f"http{"s" if secure else ""}://{host}:{port}/api/atelier/", auth=(username, password))
cookies = session.cookies.get_dict()
ws = websocket.WebSocket()
ws.connect(f"ws{"s" if secure else ""}://{host}:{port}/api/atelier/v8/%25SYS/terminal",
cookie="; ".join(["%s=%s" % (i, j) for i, j in cookies.items()]))
print(ws.recv())
ws.send(json.dumps({"type": "config", "namespace": namespace, "rawMode": False}))
print(ws.recv())
ws.send(json.dumps({"type": "prompt", "input": command}))
print(ws.recv())
ws.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Connect to VSCode Terminal and execute a command')
parser.add_argument('--username', default="_SYSTEM", help='InterSystems IRIS User')
parser.add_argument('--password', default="SYS", help='Corresponding password')
parser.add_argument('--host', default="localhost", help='IRIS Server')
parser.add_argument('--port', default=52773, help='IRIS Web Server Port')
parser.add_argument('--namespace', default="USER", help='IRIS Namespace')
parser.add_argument('--command', default="w $zv", help='IRIS Command to execute')
parser.add_argument('--secure', default=False, help='Use HTTPS/WSS')
args = parser.parse_args()
terminal(args.host, args.port, args.namespace, args.username, args.password, args.command, args.secure)
Running it produces the following output:
{"type":"init","protocol":1,"version":"IRIS for Windows (x86-64) 2025.1 (Build 223U) Tue Mar 11 2025 18:14:42 EDT"}
{"type":"prompt","text":"\u001b[1mUSER>\u001b[0m"}
{"type":"output","text":"IRIS for Windows (x86-64) 2025.1 (Build 223U) Tue Mar 11 2025 18:14:42 EDT"}
To debug the connection set ^IRIS.Temp.Atelier("terminal") to 1, all communication would be logged to the same global.
