31 lines
1.3 KiB
PowerShell
31 lines
1.3 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
|
|
$Root = "C:\UniDesk\personal-wechat"
|
|
$WcfRoot = Join-Path $Root "wcf\v39.5.2"
|
|
$StateRoot = Join-Path $Root "wcf-state"
|
|
$Python = "C:\ProgramData\miniconda3\python.exe"
|
|
$Script = Join-Path $WcfRoot "wcf_host.py"
|
|
$PidFile = Join-Path $StateRoot "wcf-host.pid"
|
|
$Stdout = Join-Path $StateRoot "wcf-host.stdout.log"
|
|
$Stderr = Join-Path $StateRoot "wcf-host.stderr.log"
|
|
|
|
New-Item -ItemType Directory -Force $StateRoot | Out-Null
|
|
|
|
if (Test-Path $PidFile) {
|
|
$oldPid = Get-Content $PidFile -ErrorAction SilentlyContinue
|
|
if ($oldPid) {
|
|
$existing = Get-Process -Id ([int]$oldPid) -ErrorAction SilentlyContinue
|
|
if ($existing) {
|
|
[pscustomobject]@{ ok = $true; alreadyRunning = $true; pid = $existing.Id; stdout = $Stdout; stderr = $Stderr } | ConvertTo-Json -Depth 4
|
|
exit 0
|
|
}
|
|
}
|
|
}
|
|
|
|
$env:WCF_COMMAND_PORT = "10086"
|
|
$env:WCF_STATE_ROOT = $StateRoot
|
|
$proc = Start-Process -FilePath $Python -ArgumentList @($Script) -WorkingDirectory $WcfRoot -WindowStyle Normal -PassThru -RedirectStandardOutput $Stdout -RedirectStandardError $Stderr
|
|
$proc.Id | Set-Content -Encoding ascii $PidFile
|
|
|
|
[pscustomobject]@{ ok = $true; started = $true; pid = $proc.Id; stdout = $Stdout; stderr = $Stderr; status = (Join-Path $StateRoot "status.json") } | ConvertTo-Json -Depth 4
|