I am seeing some odd behavior with a benchmark that has been working for years. The benchmark is for Autodesk Revit, which can use journal files to automate tasks and log times. The benchmark will read an XML file for a series of modular journal files, which can be processed in different sequences depending on what Revit features one wants to benchmark. As a result, Revit is launched with different journals, and closes at completion of each journal, to be relaunched with the next journal.
I have been using Start-Process
with the -wait
option in a loop like this...
$exitCode = (Start-Process -FilePath:$executable -argumentList:"`"$journalFile`"" -wait -errorAction:stop -PassThru).ExitCode
What has been happening of late is VERY long pauses between a journal running to completion & closing Revit and control coming back to PowerShell so the next journal can be launched. Like, sometimes 3-5 minutes, which becomes a problem when there are 10 different journal files to process. This seems to only happen in Windows 10, but I have not yet been able to verify if it's limited to a specific build, or if all Windows 10 is behaving this way.
I have found some references to Start-Process -wait
being problematic, so I started looking for alternatives.
First I tried...
$process = Start-Process -FilePath:$executable -argumentList:"`"$journalFile`""
Wait-Process $process
But this doesn't seem to actually wait. Revit is launched multiple times in parallel, and since each journal is sometimes dependent on files created in previous ones, this fails.
So then I found a reference to using [System.Diagnostics.ProcessStartInfo]
like this...
$processInfo = New-Object System.Diagnostics.ProcessStartInfo
$processInfo.RedirectStandardError = $true
$processInfo.RedirectStandardOutput = $true
$processInfo.UseShellExecute = $false
$process = New-Object System.Diagnostics.Process
with this in the loop...
$processInfo.FileName = $executable
$processInfo.Arguments = "`"$journalFile`""
$process.StartInfo = $processInfo
[Void]$process.Start()
$process.WaitForExit()
exitCode = $process.ExitCode
This seems to solve the wait problem, but results in Revit failing to process one particular journal, always at exactly the same place. But that makes no sense, as I assume Revit can have no awareness of how it was launched.
Does anyone have any suggestions on either what I might be doing wrong with either of these approaches, or a third option that I should try? And, does anyone have some solid information about what is "wrong" with Start-Process -wait
?