在PowerShell中发出外部EXE和我的自定义对象
-
03-10-2019 - |
题
(对不起,奇怪的标题,没有提出更好的东西。)
背景
我使用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
)
我想以某种方式返回有关运行的每个测试案例的信息(信息存储在 /xml文件中) PSObject
对象。
问题
您是否有任何提示如何返回信息并仍然让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
编辑:当然,如果应该重复使用外部输出,这还不够
不隶属于 StackOverflow