# go_example_1.ps1 — Start CanService + Paste example, open browser $ErrorActionPreference = "Stop" $root = $PSScriptRoot # Kill any leftover processes on our ports Write-Host "Cleaning up stale processes..." -ForegroundColor Yellow Get-NetTCPConnection -LocalPort 3210 -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue } Get-NetTCPConnection -LocalPort 3211 -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue } Start-Sleep -Milliseconds 500 Write-Host "Building CanService..." -ForegroundColor Cyan cargo build --manifest-path "$root\Cargo.toml" Write-Host "Building Paste example..." -ForegroundColor Cyan cargo build --manifest-path "$root\examples\paste\Cargo.toml" # Start CanService in background Write-Host "Starting CanService on port 3210..." -ForegroundColor Green $canService = Start-Process -FilePath "cargo" ` -ArgumentList "run --manifest-path `"$root\Cargo.toml`"" ` -WorkingDirectory $root ` -PassThru -NoNewWindow # Wait for CanService to be ready Write-Host "Waiting for CanService..." -ForegroundColor Yellow $ready = $false for ($i = 0; $i -lt 30; $i++) { try { $null = Invoke-WebRequest -Uri "http://127.0.0.1:3210/api/v1/can/0/list" -TimeoutSec 1 -ErrorAction Stop $ready = $true break } catch { Start-Sleep -Milliseconds 500 } } if (-not $ready) { Write-Host "CanService failed to start within 15s" -ForegroundColor Red Stop-Process -Id $canService.Id -Force -ErrorAction SilentlyContinue exit 1 } Write-Host "CanService ready." -ForegroundColor Green # Start Paste example (it opens the browser itself) Write-Host "Starting Paste on port 3211..." -ForegroundColor Green $paste = Start-Process -FilePath "cargo" ` -ArgumentList "run --manifest-path `"$root\examples\paste\Cargo.toml`"" ` -WorkingDirectory $root ` -PassThru -NoNewWindow Write-Host "" Write-Host "Running:" -ForegroundColor Cyan Write-Host " CanService -> http://127.0.0.1:3210" Write-Host " Paste UI -> http://127.0.0.1:3211" Write-Host "" Write-Host "Press Ctrl+C to stop both." -ForegroundColor Yellow # Wait for either process to exit, then clean up both try { while (-not $canService.HasExited -and -not $paste.HasExited) { Start-Sleep -Seconds 1 } } finally { Write-Host "Shutting down..." -ForegroundColor Yellow Stop-Process -Id $canService.Id -Force -ErrorAction SilentlyContinue Stop-Process -Id $paste.Id -Force -ErrorAction SilentlyContinue }