import os
import sys
import subprocess
from pathlib import Path

def main():
    root_dir = Path(__file__).resolve().parent.parent
    py_exe = r"C:\Users\Admin\AppData\Local\Programs\Python\Python311\python.exe"
    script = str(root_dir / "tools" / "autonomous_map_runner.py")
    
    log_path = str(root_dir / "captures" / "map_run_session.log")
    with open(log_path, "w", encoding="utf-8") as f:
        f.write("=== Launching Autonomous Map Runner ===\n")
    
    with open(log_path, "a", encoding="utf-8") as f:
        proc = subprocess.Popen(
            [py_exe, script, "--duration", "60", "--interval", "3.0"],
            stdout=f,
            stderr=subprocess.STDOUT,
            cwd=str(root_dir)
        )
        proc.wait()

if __name__ == "__main__":
    main()
