Git Product home page Git Product logo

Comments (6)

SteveL-MSFT avatar SteveL-MSFT commented on June 3, 2024 1

That works for output (or STDOUT), but we don't have 2| for error stream so you have to use 2> which only writes to files currently. Although we have #20381 which would allow redirection to a variable and during that code review I thought of this.

from powershell.

SteveL-MSFT avatar SteveL-MSFT commented on June 3, 2024 1

so you have to use 2> which only writes to files currently

If you use *>&1 you can filter for ErrorRecord in the success output. Example.

Yes, but sometimes you want (foo 2>variable:stderr) >variable:stdout

There's also #21565 for those that want tee-object for errors

from powershell.

rhubarb-geek-nz avatar rhubarb-geek-nz commented on June 3, 2024

One can simply pipe through Set-Variable if you want that

PS>  'foo' | Set-Variable 'bar'
PS> echo $bar
foo

No?

from powershell.

rhubarb-geek-nz avatar rhubarb-geek-nz commented on June 3, 2024

so you have to use 2> which only writes to files currently

If you use *>&1 you can filter for ErrorRecord in the success output. Example.

from powershell.

jborean93 avatar jborean93 commented on June 3, 2024

I agree this would be great to have, I currently use the following to capture stdout/stderr as separate vars

$stdout = $null
$stderr = . { my.exe | Set-Variable -Name stdout } 2>&1 | ForEach-Object ToString

The ForEach-Object ToString is only needed for WinPS to capture stderr as a string and not the ErrorRecords in the stream. Having a way to do it directly with redirection would be really nice as I can avoid the above complexity.

from powershell.

mklement0 avatar mklement0 commented on June 3, 2024

@jborean93, the more succinct cross-edition formulation of your code is:

$stdout, [string[]] $stderr = (my.exe 2>&1).Where({ $_ -is [string] }, 'Split')

What #20381 now enables:

my.exe 1> variable:stdout 2> variable:stderr

Alternatively:

$stdout = my.exe 2> variable:stderr

That is, #20381 is sufficient for targeting variables via redirections, via the variable: drive.

The issue at hand is about generalizing this approach, allowing any provider's items as the target.

from powershell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.