나는 C# 응용 프로그램에서 Powershell 테스트 스크립트를 실행하고 있습니다. 스크립트는 잘못된 cmdlet으로 인해 실패 할 수 있으며 이로 인해 pipe.Invoke()가 예외를 throw합니다.Pipeline.Invoke throws 후 C#에서 Powershell 출력 캡처
예외에 대해 필요한 모든 정보를 캡처 할 수 있지만 그 시점까지 스크립트 출력을 표시 할 수 있기를 바랍니다. 예외가 throw 될 때 결과가 null 인 것으로 보이기 때문에 나는 운이 없었습니다.
내가 누락 된 자료가 있습니까? 감사!
m_Runspace = RunspaceFactory.CreateRunspace();
m_Runspace.Open();
Pipeline pipe = m_Runspace.CreatePipeline();
pipe.Commands.AddScript(File.ReadAllText(ScriptFile));
pipe.Commands.Add("Out-String");
try {
results = pipe.Invoke();
}
catch (System.Exception)
{
m_Runspace.Close();
// How can I get to the Powershell output that comes before the exception?
}
좋은 물건, 내가 찾고 있었던 정확하게 것. 감사. –