1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-29 04:23:26 +00:00

fix(pwsh): avoid potential deadlock in init (#4335)

This commit is contained in:
David Knaack 2022-09-08 23:18:50 +02:00 committed by GitHub
parent 1e284347fa
commit fd5539796f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,15 +53,21 @@ $null = New-Module starship {
}
$process = [System.Diagnostics.Process]::Start($startInfo)
# Read the output and error streams asynchronously
# Avoids potential deadlocks when the child process fills one of the buffers
# https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=net-6.0#remarks
$stdout = $process.StandardOutput.ReadToEndAsync()
$stderr = $process.StandardError.ReadToEndAsync()
[System.Threading.Tasks.Task]::WaitAll(@($stdout, $stderr))
# stderr isn't displayed with this style of invocation
# Manually write it to console
$stderr = $process.StandardError.ReadToEnd().Trim()
if ($stderr -ne '') {
if ($stderr.Result.Trim() -ne '') {
# Write-Error doesn't work here
$host.ui.WriteErrorLine($stderr)
}
$process.StandardOutput.ReadToEnd();
$stdout.Result;
}
function Enable-TransientPrompt {