开发者

Output from external exe and my custom objects in powershell

(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 pos开发者_开发知识库sibility 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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜