【发布时间】:2009-08-05 14:31:43
【问题描述】:
我正在从 C# 应用程序运行 Powershell 测试脚本。该脚本可能会由于导致 pipe.Invoke() 引发异常的错误 cmdlet 而失败。
我能够捕获我需要的关于异常的所有信息,但我希望能够显示该脚本的输出。我没有任何运气,因为抛出异常时结果似乎为空。
我有什么遗漏吗?谢谢!
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?
}
【问题讨论】:
标签: c# powershell powershell-1.0