You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MAI/start-hdmi-bridge.ps1

29 lines
1.1 KiB
PowerShell

$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"