Skip to content

Commit 2030341

Browse files
committed
test redirect
1 parent 887250b commit 2030341

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

.github/workflows/pull-requests.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
{
1212
"name": "check interrupt",
13-
"run": "python3 ./tools/run-with-console.py"
14-
},
13+
"run": "tools/run-test-interrupt-with-console-v3.ps1"
14+
},
1515
# {
1616
# "name": "Run interrupt",
1717
# "run": "tools/test-interrupt.sh",
@@ -188,7 +188,7 @@
188188
"bazel_os": "windows",
189189
"cross_compile": false,
190190
"lint": false,
191-
"os": "windows-2025",
191+
"os": "windows-2022",
192192
"platform_name": "windows_amd64",
193193
"upload": false
194194
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
$TempBatFile = Join-Path ([System.IO.Path]::GetTempPath()) "run_bash_$(Get-Random).bat"
2+
$CurrentWorkingDirectory = Get-Location
3+
$BatchContent = @"
4+
@echo off
5+
echo %cd%
6+
cd "$CurrentWorkingDirectory"
7+
"C:\Program Files\Git\bin\bash.exe" -c "./tools/test-interrupt.sh"
8+
exit /b %ERRORLEVEL%
9+
"@
10+
11+
try {
12+
$BatchContent | Out-File -FilePath $TempBatFile -Encoding ASCII
13+
14+
# Use conhost.exe to run the batch file with output capture
15+
$ProcessStartInfo = New-Object System.Diagnostics.ProcessStartInfo
16+
$ProcessStartInfo.FileName = "conhost.exe"
17+
$ProcessStartInfo.Arguments = "`"$TempBatFile`""
18+
$ProcessStartInfo.RedirectStandardOutput = $true
19+
$ProcessStartInfo.RedirectStandardError = $true
20+
$ProcessStartInfo.UseShellExecute = $false
21+
$ProcessStartInfo.CreateNoWindow = $false
22+
23+
# Start the process
24+
$Process = New-Object System.Diagnostics.Process
25+
$Process.StartInfo = $ProcessStartInfo
26+
$OutputAction = {
27+
if ($Event.SourceEventArgs.Data -ne $null) {
28+
Write-Host $Event.SourceEventArgs.Data -ForegroundColor Green
29+
}
30+
}
31+
$ErrorAction = {
32+
if ($Event.SourceEventArgs.Data -ne $null) {
33+
Write-Host $Event.SourceEventArgs.Data -ForegroundColor Red
34+
}
35+
}
36+
$OutputEvent = Register-ObjectEvent -InputObject $Process -EventName OutputDataReceived -Action $OutputAction
37+
$ErrorEvent = Register-ObjectEvent -InputObject $Process -EventName ErrorDataReceived -Action $ErrorAction
38+
39+
try {
40+
$Process.Start() | Out-Null
41+
$Process.BeginOutputReadLine()
42+
$Process.BeginErrorReadLine()
43+
44+
Write-Host "Started conhost process with PID: $($Process.Id)"
45+
46+
# Wait for the process to complete
47+
$Process.WaitForExit()
48+
$ExitCode = $Process.ExitCode
49+
50+
Write-Host ""
51+
Write-Host "Process completed with exit code: $ExitCode"
52+
53+
exit $ExitCode
54+
}
55+
finally {
56+
# Clean up event handlers
57+
if ($OutputEvent) { Unregister-Event -SourceIdentifier $OutputEvent.Name }
58+
if ($ErrorEvent) { Unregister-Event -SourceIdentifier $ErrorEvent.Name }
59+
60+
# Dispose of the process
61+
if ($Process) { $Process.Dispose() }
62+
}
63+
}
64+
catch {
65+
Write-Error "Error starting process: $_"
66+
exit 1
67+
}
68+
finally {
69+
Remove-Item $TempBatFile -Force -ErrorAction SilentlyContinue
70+
}

0 commit comments

Comments
 (0)