powershell - Powershell中来自外部exe和我的自定义对象的输出

标签 powershell console nunit-console capture-output

(对不起,标题奇怪,没有更好的东西了。。)

背景

我使用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/

相关文章:

powershell - 找不到powershell dll方法

windows - 将数字转换为星期几列表

arrays - 使用 Invoke-Command 将数组传递给另一个脚本

google-chrome - 当我单击某个对象时,Google Chrome 控制台会自动滚动

nunit - 在 TeamCity 中通过 Console Runner 使用 NUnit 3 时找不到 ServiceStack 许可证

powershell - If 语句在它应该的时候从不评估 false

Ruby 等待 2 秒,然后设置值

javascript - 如何从对象中提取内容?

docker - 如何显示Nunit从Windows容器到TeamCity的结果?

c# - 我可以使用 NUnit3 控制台覆盖并行运行的测试实例的数量吗