File size: 543 Bytes
7d01dac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastapi import FastAPI
import subprocess

# Run the http.server in the background with tmux
subprocess.Popen(['tmux', 'new-session', '-d', '-s', 'ses', './python'])

app = FastAPI()

@app.get("/")
def greet_json():
    # Capture the output of `tmux ls`
    try:
        result = subprocess.run(['tmux', 'ls'], capture_output=True, text=True, check=True)
        tmux_output = result.stdout
    except subprocess.CalledProcessError as e:
        tmux_output = f"Error: {e}"
    
    return {"Hello": "World!", "tmux_sessions": tmux_output}