该
RedirectStandardError属性上的文档建议最好将
WaitForExit()呼叫放在呼叫之后
ReadToEnd()。以下内容对我来说是正确的:
$psi = New-object System.Diagnostics.ProcessStartInfo $psi.CreateNoWindow = $true $psi.UseShellExecute = $false $psi.RedirectStandardOutput = $true $psi.RedirectStandardError = $true $psi.FileName = 'ipconfig.exe' $psi.Arguments = @("/a") $process = New-Object System.Diagnostics.Process $process.StartInfo = $psi [void]$process.Start()$output = $process.StandardOutput.ReadToEnd() $process.WaitForExit() $output


