function return values, console output


  1.    21 Aug 2006 #1
    =?Utf-8?B?ZnV6enkzMzM=?= Guest

    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 SpecsSystem Spec

  2.    21 Aug 2006 #2
    =?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?= Guest

    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 SpecsSystem Spec

  3.    21 Aug 2006 #3
    Keith Hill [MVP] Guest

    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 SpecsSystem Spec

  4.    22 Aug 2006 #4
    =?Utf-8?B?ZnV6enkzMzM=?= Guest

    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 SpecsSystem Spec

function return values, console output

Similar Threads
Thread Forum
Re: Perform OR operation on function return values
On May 27, 5:05pm, "M" <m...@newsgroup> wrote: The function parameters need to be enclosed in parentheses, as in ... If...
VB Script
Script running other scripts return values
hello I've got series of VB scripts that I run manually buy clicking on them, Can't I have one script that runs all of them? I would want to...
VB Script
Return values from functions
I usually like PowerShell very much but there is one feature I absolutely hate: PowerShell returns any output within a function. I have the...
PowerShell
How to combine/return multiple values from a sql query
Hi guys. I've been stuck on this for a while as a newb, so please forgive me in advance. Any help would be very appreciated. I wrote a little...
VB Script
Associative Array - how to return mapped values?
Hello PowerShellers, How do I return a mapped value from an associative array? I have this books.csv file: ID,Author,Title 1,"Dr...
PowerShell
BUG: Redirecting function contents to a file truncates function lines at the width of the console
In my profile.ps1 file, I have various functions with line widths greater than 80 columns. My console is 80 columns. If I use the following: ...
PowerShell
function: Showing valid parameter values for a set
I can't recall seeing anyone post a simple-wrapup tool for displaying valid allowed parameter values where the parameter has the...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 23:43.
    .