question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PSCore: Linux - Clear-Host injects data into function return value

See original GitHub issue

Steps 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
iSazonovcommented, Oct 2, 2019

@mklement0 Many thanks! I pulled PR with your suggestion.

2reactions
iSazonovcommented, Oct 2, 2019

@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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found