PowerShell / PowerShell/PowerShell
Experimental `PSRedirectToVariable` feature: target variable isn't cleared if the captured stream has no output
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
The experimental PSRedirectToVariable feature conveniently allows capturing stream output via > and >> in variables, e.g. >variable:stdout.
If the targeted stream has no output, the variable should be cleared to indicate that fact (if appending is desired, >> can be used).
However, any preexisting variable value currently unexpectedly lingers.
# Note: Enable-ExperimentalFeature PSRedirectToVariable must be in effect
# (turning it on requires starting a new session.)
$stdout = 'psych!'
whoami -nosuch >variable:stdout 2>$ull
$stdout
Expected behavior
No output, because no stdout output was received, which should set $stdout to the enumerable null ([System.Management.Automation.Internal.AutomationNull]::Value), whether or not the variable previously existed.
This would be consistent with the behavior of direct assignments; e.g., $stdout = & {} properly records the enumerable null.
Actual behavior
psych!
That is, the preexisting value of the target variable unexpectedly lingered.
Error details
No response
Environment data
PowerShell 7.5.0-rc.1
Visuals
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Enable the PSRedirectToVariable experimental feature and run the reproduction using $stdout, whoami -nosuch, and >variable:stdout. Trace the PSRedirectToVariable handling for a stream with no output, then verify that an existing target variable becomes the enumerable null and that the append behavior remains distinct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100