Exiting external exe and my custom objects in powershell
(Sorry for the weird title, didn't think of anything better ..)
Background
I am using 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 great.
Problem
nunit-console
should output my messages so far. This means that if it was not captured, it must send them to the screen, otherwise it can be saved in file ( Test-ByNunit $dll | set-content path
)
I would like to somehow return information about each test script that is running (the information is stored in the / xml file) as an array of objects PSObject
.
Question
Do you have a hint on how to return information and leave nunit to output its messages?
If I just write it for output, the function returns an array of strings (output from nunit-console) and an array of my objects. Then redirecting to the output file will save my objects as well, but I would like to just display them in the console window.
The only opportunity that could work is to use it [ref]
, but I would like to avoid it.
(this is not just about nunit-console, but of course this is a general question)
a source to share
If I received the task correctly, then I 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 the outer output also needs to be reused and not just shown
a source to share