Comments (6)
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.
so you have to use
2>
which only writes to files currentlyIf you use
*>&1
you can filter forErrorRecord
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.
One can simply pipe through Set-Variable if you want that
PS> 'foo' | Set-Variable 'bar'
PS> echo $bar
foo
No?
from powershell.
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.
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.
@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)
- Mount-DiskImage does not assign driver letter every third time HOT 2
- Does PowerShell support the real "Stream" response? HOT 5
- v7.4.2 not in Ubuntu 22.04 Linux package repository for Microsoft products HOT 3
- `Finally` block isn't executed upon Ctrl+C HOT 36
- Make `ConvertFrom-StringData` more error tolerant HOT 9
- Add-Type ReferencedAssemblies only works with full file paths now? HOT 1
- .Net 8 in PowerShell 7 System.Private.CoreLib fails to register. HOT 41
- `ConvertFrom-StringData` mistakenly emits a statement-terminating error when one of its input strings isn't well-formed HOT 2
- Update from System.Data.SqlClient to Microsoft.Data.SqlClient HOT 3
- .NET App using Powershell.SDK fails to run, when building as SingeFile HOT 2
- Add a command which gets the System Lockdown mode information HOT 2
- Overriding .NETs ToString() method can cause unexpected behaviour when using Transcripts HOT 1
- `Compare-Object` doesn't compare custom value types (`structs`) (that don't implement `IComparable`) correctly HOT 4
- Invoke-WebRequest needs SupportsShouldProcess
- using `Get-AppxPackage` when `SYSTEMDRIVE` env var is not set creates a (literal) `%SystemDrive%/…` directory HOT 7
- Get-Help shows incorrect spacing and unwanted prefixes for first line of .EXAMPLE text HOT 6
- Argument with colon in it is incorrectly handled if not quoted HOT 12
- Get-AuthenticodeSignature needs to use embedded signatures HOT 5
- Save-PSResource doesn't install the correct version. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powershell.