28 lines
716 B
Python
28 lines
716 B
Python
#!/usr/bin/env python3
|
|
import subprocess
|
|
import sys
|
|
import json
|
|
|
|
args = json.loads(sys.stdin.read())
|
|
command = args.get("command", "")
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
["bash", "-c", command],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=120,
|
|
)
|
|
output = result.stdout
|
|
if result.stderr:
|
|
output += f"\n[stderr] {result.stderr}"
|
|
if result.returncode != 0:
|
|
output += f"\n[exit code: {result.returncode}]"
|
|
if len(output) > 2000:
|
|
output = output[:2000] + "\n[output truncated]"
|
|
print(output.strip() or "[no output]")
|
|
except subprocess.TimeoutExpired:
|
|
print("[command timed out after 120s]")
|
|
except Exception as e:
|
|
print(f"[error: {e}]")
|