I'm currently working on a PowerShell script that includes the line
$process1 = Start-Process -FilePath ($exePath1) -PassThru -RedirectStandardError ($logPath1)
Which starts a long-running process and redirects the process' StandardError to a log file. My problem is that this also apparently interferes with ExitCode.
$process1.ExitCode
returns null after the process has exited. If I remove "RedirectStandardError ($logPath1)" then ExitCode returns the value my dummy-program is expected to return.
Should I be doing something different? I'm hoping to be able to start the process (redirecting the StandardError to the log file for diagnostics), wait a few seconds to make sure it doesn't crash, and retrieve the ErrorCode in the event that it does.
$process1.WaitForExit()firstly before obtaining the$process1.ExitCode.