34 lines
1.2 KiB
PowerShell
34 lines
1.2 KiB
PowerShell
$log = "C:\Users\Administrator\Desktop\nanxiang1\run_logs\backend-10000.log"
|
|
New-Item -ItemType Directory -Force -Path "C:\Users\Administrator\Desktop\nanxiang1\run_logs" | Out-Null
|
|
if (Test-Path $log) {
|
|
Remove-Item $log -Force
|
|
}
|
|
|
|
$psi = New-Object System.Diagnostics.ProcessStartInfo
|
|
$psi.FileName = "C:\Users\Administrator\Miniforge3\python.exe"
|
|
$psi.Arguments = "-m uvicorn app.main:app --app-dir backend --host 127.0.0.1 --port 10000"
|
|
$psi.WorkingDirectory = "C:\Users\Administrator\Desktop\nanxiang1"
|
|
$psi.UseShellExecute = $false
|
|
$psi.RedirectStandardOutput = $true
|
|
$psi.RedirectStandardError = $true
|
|
|
|
$process = New-Object System.Diagnostics.Process
|
|
$process.StartInfo = $psi
|
|
$null = $process.Start()
|
|
|
|
Start-Sleep -Seconds 5
|
|
|
|
if (-not $process.HasExited) {
|
|
$stdout = $process.StandardOutput.ReadExisting()
|
|
$stderr = $process.StandardError.ReadExisting()
|
|
Set-Content -Path $log -Value ($stdout + $stderr) -Encoding UTF8
|
|
Write-Output "STARTED_PID=$($process.Id)"
|
|
Get-Content $log
|
|
} else {
|
|
$stdout = $process.StandardOutput.ReadToEnd()
|
|
$stderr = $process.StandardError.ReadToEnd()
|
|
Set-Content -Path $log -Value ($stdout + $stderr) -Encoding UTF8
|
|
Write-Output "EXITED_CODE=$($process.ExitCode)"
|
|
Get-Content $log
|
|
}
|