【发布时间】:2014-04-24 05:51:11
【问题描述】:
我正在通过我的代码中的管道执行交换 powershell 命令。
问题是当命令直接在powershell上执行时,返回的错误是四行长,但是当我通过管道运行命令时,它只返回错误消息的第一行。
这是我目前的代码:
bool ps_calls::check_invoke(Pipeline^ pipeline)
{
if (pipeline->Error->Count <= 0)
return true;
Collection<System::Object^> errorCollection = pipeline->Error->ReadToEnd();
for (int i=0; i< errorCollection.Count; i++)
{
String^ msg = String::Format("Error {0}",errorCollection[i]->ToString());
m_errors->Add(msg);
m_logger->info_msg(String::Format("ERROR: {0}", msg));
}
return false;
}
这是我的管道现在返回的示例:
ERROR: Error The operation couldn't be performed because object 'Testing' couldn't be found on 'server'.
这是一个示例,如果在 powershell 控制台上手动执行相同的命令,则会出现错误消息:
The operation couldn't be performed because object 'test' couldn't be found on 'server'.
+ CategoryInfo : NotSpecified: (:) [Get-MailboxDatabase], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : 2F753561,Microsoft.Exchange.Management.SystemConfigurationTasks.GetMailboxDatabase
+ PSComputerName : server
我也希望能够获取此错误消息的其余部分,以便在发生错误时看到 ErrorID。
【问题讨论】:
标签: c++ powershell c++-cli