• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

function return values, console output

  • Thread starter =?Utf-8?B?ZnV6enkzMzM=?=
  • Start date
?

=?Utf-8?B?ZnV6enkzMzM=?=

#1
I'm trying to figure out how to run msbuild in a function and have this
function return true or false indicating msbuild's success or failure.
Also important, I want the normal output of the command (streaming and
with intended foregroung/background color) to appear in the console as
msbuild is running so, for example:

# ---------------------------------
function Compile() {
msbuild
if( $LastErrorCode -eq 0 ) {
return $true
} else {
return $false
}
}

#$compileSuccess = Compile
Compile

Calling "Compile" without assigning it to a variable I get the behavior that
I'm looking for, but no return value. However calling Compile and assigning
the return value to $compileSucsess as in the commented line in the example
causes all output from msbuild from to be stored in $compileSuccess variable,
not just the boolean return value, and msbuild's output doesn't appear in the
console as intended.

So how can I acheive the behavior I'm looking for? Is there a way to simply
return a value, not all output from the function?
 

My Computer

?

=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=

#2
You are putting the output and the boolean to the pipeline
(return is optional all output gets returned.

you can use

MSbuild | out-host

this will output the test to the console but not the pipeline

MowPS>Function test {
>> ipconfig | out-host
>> if( $LastErrorCode -eq 0 ) {
>> return $true
>> } else {
>> return $false
>> }
>> }
>>

MowPS>test

Windows IP Configuration
Ethernet adapter Local Area Connection:
....

False

MowPS>$test = test

Windows IP Configuration
Ethernet adapter Local Area Connection:

MowPS>$test
False

b.t.w. this also has the lineadding bug theat is bothering a lot of the
powershell output.

Greetings /\/\o\/\/


"fuzzy333" wrote:

> I'm trying to figure out how to run msbuild in a function and have this
> function return true or false indicating msbuild's success or failure.
> Also important, I want the normal output of the command (streaming and
> with intended foregroung/background color) to appear in the console as
> msbuild is running so, for example:
>
> # ---------------------------------
> function Compile() {
> msbuild
> if( $LastErrorCode -eq 0 ) {
> return $true
> } else {
> return $false
> }
> }
>
> #$compileSuccess = Compile
> Compile
>
> Calling "Compile" without assigning it to a variable I get the behavior that
> I'm looking for, but no return value. However calling Compile and assigning
> the return value to $compileSucsess as in the commented line in the example
> causes all output from msbuild from to be stored in $compileSuccess variable,
> not just the boolean return value, and msbuild's output doesn't appear in the
> console as intended.
>
> So how can I acheive the behavior I'm looking for? Is there a way to simply
> return a value, not all output from the function?
 

My Computer

K

Keith Hill [MVP]

#3
"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:3B33C30E-393F-4398-A9FF-0323EC388D41@microsoft.com...
> b.t.w. this also has the lineadding bug theat is bothering a lot of the
> powershell output.


You can say that again. :-)

--
Keith
 

My Computer

?

=?Utf-8?B?ZnV6enkzMzM=?=

#4
Thanks for replying but this doesn't address the issue.Using out-host in this
manner causes output to be buffered before it get to out-host, so it appears
in one big glob when msbuild is done, and all of the coloring that is done by
msbuild to it's output is also lost in this scenario.

Here's a little something I found though.
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=77986&SiteID=99
I think this addresses what I want, simply that msbuild writes to the
console directly, which would allow it to behave exactly as it did in cmd.exe.

"/\/\o\/\/ [MVP]" wrote:

> You are putting the output and the boolean to the pipeline
> (return is optional all output gets returned.
>
> you can use
>
> MSbuild | out-host
>
> this will output the test to the console but not the pipeline
>
> MowPS>Function test {
> >> ipconfig | out-host
> >> if( $LastErrorCode -eq 0 ) {
> >> return $true
> >> } else {
> >> return $false
> >> }
> >> }
> >>

> MowPS>test
>
> Windows IP Configuration
> Ethernet adapter Local Area Connection:
> ...
>
> False
>
> MowPS>$test = test
>
> Windows IP Configuration
> Ethernet adapter Local Area Connection:
>
> MowPS>$test
> False
>
> b.t.w. this also has the lineadding bug theat is bothering a lot of the
> powershell output.
>
> Greetings /\/\o\/\/
>
>
> "fuzzy333" wrote:
>
> > I'm trying to figure out how to run msbuild in a function and have this
> > function return true or false indicating msbuild's success or failure.
> > Also important, I want the normal output of the command (streaming and
> > with intended foregroung/background color) to appear in the console as
> > msbuild is running so, for example:
> >
> > # ---------------------------------
> > function Compile() {
> > msbuild
> > if( $LastErrorCode -eq 0 ) {
> > return $true
> > } else {
> > return $false
> > }
> > }
> >
> > #$compileSuccess = Compile
> > Compile
> >
> > Calling "Compile" without assigning it to a variable I get the behavior that
> > I'm looking for, but no return value. However calling Compile and assigning
> > the return value to $compileSucsess as in the commented line in the example
> > causes all output from msbuild from to be stored in $compileSuccess variable,
> > not just the boolean return value, and msbuild's output doesn't appear in the
> > console as intended.
> >
> > So how can I acheive the behavior I'm looking for? Is there a way to simply
> > return a value, not all output from the function?
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)