c++ -CLI Pipeline只返回错误消息的第一行
C++-CLI Pipeline only returns the first row of the error message
我正在通过代码中的管道执行exchange 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,当错误发生
PowerShell在格式化时不调用ToString,这就是为什么你看不到相同的输出。
一些主机应用程序通常将输出管道输出到Out-Default -如果您这样做,您将看到预期的错误格式。
其他主机应用程序将输出管道输出到Out-String -这将以与管道输出到Out-Default相同的方式格式化对象,但您将获得一个字符串对象,您可以根据需要记录。
相关文章:
- boost::进程间消息队列引发错误
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- 从C++dll访问C#中的一行主要参数
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 在C++中,我如何接受不同于同一行的用户输入
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何从一行中读取特定数量的字符?(C++)
- 如何通过参数抛出错误消息
- 从服务器传输到客户端的消息不会出现
- ROS2 动态消息模板
- 读取最后一行代码算法 - c++ 时出现问题
- 查找矩阵C++中每一列和每一行的最小和最大元素
- C++秘密消息学校作业
- 在一行中断言:AreEqual格式的消息
- GCC:为什么一行代码中的错误(字符串和NULL的比较)会导致一长串错误消息
- c++ -CLI Pipeline只返回错误消息的第一行