![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | function return values, console output 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 System Specs![]() |
| | #2 (permalink) |
| | RE: function return values, console output 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 System Specs![]() |
| | #3 (permalink) |
| | Re: function return values, console output "/\/\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 System Specs![]() |
| | #4 (permalink) |
| | RE: function return values, console output 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/feedba...7986&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 System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Return values from functions | PowerShell | |||
| How to combine/return multiple values from a sql query | VB Script | |||
| Associative Array - how to return mapped values? | PowerShell | |||
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | PowerShell | |||
| function: Showing valid parameter values for a set | PowerShell | |||