(对不起,标题奇怪,没有更好的东西了。。)
背景
我使用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有关,而且当然是普遍问题)
最佳答案
如果我正确完成任务,那么Out-Host
应该会有所帮助:
function Get-WithOutHost {
# external output is redirected to the host
cmd /c dir | Out-Host
# normal output to be reused later
Get-Process
}
# call
$result = Get-WithOutHost
# now $result holds the data to use, external output is on the screen
编辑:当然,如果还应该重用外部输出,这还不够,不仅仅是显示
关于powershell - Powershell中来自外部exe和我的自定义对象的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2780214/