PSCore: Linux - Clear-Host injects data into function return value
See original GitHub issueSteps to reproduce
Function Get-SomeData {
Clear-Host
$somedata="somedata"
return $somedata
}
$myData = Get-SomeData
$myData[0] # will clear the screen
$myData[1] # "somedata"
$myData.Count # will be 2
Expected behavior
Function should return a single value ("somedata")
Actual behavior
Function returns an array with the Clear-Host command as the first object
Environment data
Verified in:
Name | Value |
---|---|
PSVersion | 6.2.0 |
PSEdition | Core |
GitCommitId | 6.2.0 |
OS | Linux 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 |
Platform | Unix |
PSCompatibleVersions | 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.2.0 |
PSRemotingProtocolVersion | 2.3 |
SerializationVersion | 1.1.0.1 |
WSManStackVersion | 3.0 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Make Clear-Host clear the scrollback buffer too on all ...
Implement a switch named -All to direct Clear-Host to clear not only the current screen of terminal (console) hosts but to clear the...
Read more >Powershell: Write-Output in Function with Return Value
This occurs when I attempt to use Write-Output in a function that returns a value. So, here are two examples. This would work:...
Read more >Clear-Host (Microsoft.PowerShell.Core)
The Clear-Host function removes all text from the current display, including commands and output that might have accumulated. When complete, it displays the ......
Read more >Clear captured output/return value in a Powershell function
I worked around this by passing return variable as a reference parameter [ref] . This works consistently. Check the sample code below.
Read more >Returning value of a function--best practice? : r/bash
What is the best way to return the result of a function? I've read that e.g. echo "some value" is not recommended. Global...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mklement0 Many thanks! I pulled PR with your suggestion.
@mklement0 I see we have some issues with Clear-Host. but I still don’t have the ability to test on Unix-s and can not grab this. (Although we could do
RawUI.Clear()
step by step).