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

发布于 2024-08-31 08:31:46 字数 853 浏览 5 评论 0原文

(抱歉,标题很奇怪,没有想出更好的东西..)

背景

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角卖回忆 2024-09-07 08:31:46

如果我正确完成了任务,那么 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

编辑:当然,如果外部输出也应该重用,而不仅仅是显示,那么这还不够

If I got the task right then Out-Host should help:

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

EDIT: of course this is not enough if external output should be reused, too, not just shown

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文