外部 exe 和 powershell 中我的自定义对象的输出
(抱歉,标题很奇怪,没有想出更好的东西..)
背景
我使用 nunit-console 来测试我的程序集。它的名字是这样的(简化的):
function Test-ByNunit {
param($assembly, $tempFile = 'c:\temp\nunit.xml')
& <path-to-nunit-console> $assembly /nologo /xml:$tempFile @othparam
}
Test-ByNunit c:\temp\myAssembly.dll
我对此没有问题,它工作得很好。
问题
nunit-console
到目前为止应该输出其消息。这意味着 - 如果没有捕获,它应该将它们发送到屏幕,否则它可以存储在文件中(Test-ByNunit $dll | set-content path
)
我想以某种方式返回有关每个的信息以 PSObject
对象数组的形式运行的测试用例(信息存储在 /xml 文件中)。
问题
您是否有任何提示如何返回信息并仍然让 nunit 输出其消息?
如果我只是将其写入输出,该函数将返回字符串数组(从 nunit-console 输出)和对象数组。然后重定向到输出文件也将存储我的对象,但我只想在控制台窗口中显示它们。
唯一可行的可能性是使用 [ref]
,但我想避免它。
(这不仅仅是关于 nunit-console,当然这是一般问题)
(Sorry for strange title, haven't come up with anything better..)
Background
I use nunit-console to test my assemblies. It is called like this (simplified):
function Test-ByNunit {
param($assembly, $tempFile = 'c:\temp\nunit.xml')
& <path-to-nunit-console> $assembly /nologo /xml:$tempFile @othparam
}
Test-ByNunit c:\temp\myAssembly.dll
I have no problem with this, it works fine.
Problem
nunit-console
should output its messages as so far. That means - if not captured, it should send them to screen, otherwise it could be stored in file (Test-ByNunit $dll | set-content path
)
I'd like to return somehow information about each test-case that was run (the info is stored in the /xml file) in form of array of PSObject
objects.
Question
Do you have any tip how to return the info and still leave nunit output its messages?
If I simply write it to output, the function will return array of strings (output from nunit-console) and array of my objects. Then redirection to output file will store my objects as well, but I'd like just display them in console window.
The only possibility that could work is to use [ref]
, but I'd like to avoid it.
(this is not only about nunit-console, but of course it is general question)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确完成了任务,那么
Out-Host
应该会有所帮助:编辑:当然,如果外部输出也应该重用,而不仅仅是显示,那么这还不够
If I got the task right then
Out-Host
should help:EDIT: of course this is not enough if external output should be reused, too, not just shown