$ErrorActionPreference = 'Continue' $ProgressPreference = 'SilentlyContinue' $maxRetries = 15 $script = 'C:\sanguo_vnpy_v2\scripts\data_platform\download_15m_xtdata.py' $resultFile = 'C:\sanguo_vnpy_v2\data\minute_15\_result.json' $logFile = 'C:\sanguo_vnpy_v2\data\minute_15_download.log' $errFile = 'C:\sanguo_vnpy_v2\data\minute_15_download.err.log' $wrapperLog = 'C:\sanguo_vnpy_v2\data\minute_15_wrapper.log' function Log-W($m) { $line = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $m" Add-Content -Path $wrapperLog -Value $line -Encoding UTF8 } Log-W "WRAPPER START maxRetries=$maxRetries" for ($i = 1; $i -le $maxRetries; $i++) { Log-W "ATTEMPT $i/$maxRetries starting python" if (Test-Path $errFile) { Clear-Content $errFile -EA SilentlyContinue } try { $p = Start-Process -FilePath 'C:\Python310\python.exe' ` -ArgumentList '-X utf8', $script ` -WindowStyle Hidden ` -RedirectStandardOutput $logFile ` -RedirectStandardError $errFile ` -Wait -PassThru $ec = if ($null -ne $p.ExitCode) { $p.ExitCode } else { -999 } } catch { $ec = -998 Log-W "Start-Process exception: $_" } Log-W "ATTEMPT $i exited code=$ec" if (Test-Path $resultFile) { Log-W "_result.json EXISTS - DONE" break } Log-W "no result yet, sleeping 8s before retry..." Start-Sleep -Seconds 8 } Log-W "WRAPPER EXIT"