| 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() | |
| 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} |