我从C#应用程序运行Powershell测试脚本。由于导致pipe.Invoke()抛出异常的错误cmdlet,该脚本可能会失败。在Pipeline.Invoke后捕获C#中的Powershell输出
我能够捕获我需要的有关异常的所有信息,但我希望能够显示该脚本的输出。我没有任何运气,因为在引发异常时结果似乎为空。
有什么我失踪了吗?谢谢!
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?
}
不错,我正在寻找。谢谢。 – 2012-07-23 08:34:34