$ErrorActionPreference = "Stop" $Root = Split-Path -Parent $MyInvocation.MyCommand.Path $Python = Join-Path $Root ".venv\Scripts\python.exe" $PidFile = Join-Path $Root "runtime-data\hdmi_bridge.pid" $LogDir = Join-Path $Root "runtime-data\logs" $Stdout = Join-Path $LogDir "hdmi_bridge.log" $Stderr = Join-Path $LogDir "hdmi_bridge.err.log" New-Item -ItemType Directory -Force -Path $LogDir | Out-Null if (Test-Path -LiteralPath $PidFile) { $RunningPid = [int](Get-Content -LiteralPath $PidFile -Raw) if (Get-Process -Id $RunningPid -ErrorAction SilentlyContinue) { Write-Output "HDMI USB bridge already running: PID $RunningPid" exit 0 } } $Process = Start-Process ` -FilePath $Python ` -ArgumentList @("-u", (Join-Path $Root "hdmi_usb_bridge.py"), "--port", "8091") ` -WorkingDirectory $Root ` -WindowStyle Hidden ` -RedirectStandardOutput $Stdout ` -RedirectStandardError $Stderr ` -PassThru Set-Content -LiteralPath $PidFile -Value $Process.Id -Encoding ascii Write-Output "HDMI USB bridge started: PID $($Process.Id), http://localhost:8091"