mirror of
https://github.com/OS-Copilot/OS-Copilot.git
synced 2026-05-05 03:00:15 -04:00
18 lines
529 B
Python
18 lines
529 B
Python
from fastapi import APIRouter
|
|
from pydantic import BaseModel
|
|
import subprocess
|
|
|
|
router = APIRouter()
|
|
|
|
class ShellCommandModel(BaseModel):
|
|
command: str
|
|
|
|
class ShellCommandResultModel(BaseModel):
|
|
stdout: str
|
|
stderr: str
|
|
|
|
@router.post("/tools/shell", response_model=ShellCommandResultModel)
|
|
async def execute_shell_command(command: ShellCommandModel):
|
|
result = subprocess.run(command.command, capture_output=True, shell=True, text=True)
|
|
return ShellCommandResultModel(stdout=result.stdout, stderr=result.stderr)
|