Skip to content

Commit a84f4ec

Browse files
committed
Use system process to avoid false wait times
1 parent fa131b7 commit a84f4ec

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,37 +1492,34 @@ function Start-UnityEditor {
14921492
$unityArgs = $sharedArgs | ForEach-Object { $_ }
14931493
if ( $instanceArgs[$i] ) { $unityArgs += $instanceArgs[$i] }
14941494

1495-
$setProcessArgs = @{
1496-
'FilePath' = $editor;
1497-
'PassThru' = $true;
1498-
'ErrorAction' = 'Stop';
1499-
'RedirectStandardOutput' = New-TemporaryFile;
1500-
'RedirectStandardError' = New-TemporaryFile;
1501-
}
1502-
1503-
if ($Wait) { $setProcessArgs['Wait'] = $true }
1504-
1505-
Write-Verbose "Redirecting standard output to $($setProcessArgs['RedirectStandardOutput'])"
1506-
Write-Verbose "Redirecting standard error to $($setProcessArgs['RedirectStandardError'])"
1507-
15081495
$actionString = "$editor $unityArgs"
1509-
if( $Credential ) { $actionString += " -password (hidden)"}
1510-
if( $Serial ) { $actionString += " -serial (hidden)"}
1496+
if ( $Credential ) { $actionString += " -password (hidden)"}
1497+
if ( $Serial ) { $actionString += " -serial (hidden)"}
15111498

1512-
if (-not $PSCmdlet.ShouldProcess($actionString, "Start-Process")) {
1499+
if (-not $PSCmdlet.ShouldProcess($actionString, "System.Diagnostics.Process.Start()")) {
15131500
continue
15141501
}
15151502

15161503
# Defered till after potential display by ShouldProcess
15171504
if ( $Credential ) { $unityArgs += '-password', $Credential.GetNetworkCredential().Password }
15181505
if ( $Serial ) { $unityArgs += '-serial', [System.Net.NetworkCredential]::new($null, $Serial).Password }
15191506

1520-
if ($unityArgs -and $unityArgs.Length -gt 0) {
1521-
$setProcessArgs['ArgumentList'] = $unityArgs
1522-
}
1523-
1524-
$process = Start-Process @setProcessArgs
1507+
# We've experienced issues with Start-Process -Wait and redirecting
1508+
# output so we're using the Process class directly now.
1509+
$process = New-Object System.Diagnostics.Process
1510+
$process.StartInfo.Filename = $editor
1511+
$process.StartInfo.Arguments = $unityArgs
1512+
$process.StartInfo.RedirectStandardOutput = $true
1513+
$process.StartInfo.RedirectStandardError = $true
1514+
$process.StartInfo.UseShellExecute = $false
1515+
$process.StartInfo.CreateNoWindow = $true
1516+
$process.StartInfo.WorkingDirectory = $PWD
1517+
$process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
1518+
$process.Start() | Out-Null
1519+
15251520
if ( $Wait ) {
1521+
$process.WaitForExit()
1522+
15261523
if ( $LogFile -and (Test-Path $LogFile -Type Leaf) ) {
15271524
# Note that Unity sometimes returns a success ExitCode despite the presence of errors, but we want
15281525
# to make sure that we flag such errors.

0 commit comments

Comments
 (0)