0

The output of many commands in PS get dumped onto the display so abruptly, I don't even remember what command I typed-in. I have to scroll up a few pages to see.

Is it possible to slow the output stream down, so we can read it as it passes by on the screen? ..even if it's an error, if it comes in a civilized and readable stream, like closed captioning on C-SPAN, we could make better sense of even seemingly boring messages...

"More" works but it's a whole page at a time.

I also found this at techrepublic:

function EasyView { process { $_; Start-Sleep -seconds .5}}

Get-ChildItem C: | EasyView 

which is cool but it outputs 1 full record at a time..

I'm looking for streaming, 1 letter every .5 seconds for example. Like in the Matrix, or better yet like in War Games with Matthew Broderick...

Any thoughts?

Danny
  • 33
  • 7
  • 1
    The way this usually works with a command line is that you don't want to slow down the output (especially if there's a few pages of output). Instead, you say `whatever_command > output.txt 2> errors.txt`, and you can open and read the text files at your leisure. Or have you already tried that approach? – Teepeemm Jun 24 '15 at 00:17
  • 2
    `out-host -paging` which is the PS equivalent to `more` should be what you want. Hit enter instead of space and you will progress one line at a time. [`Get-History` or just `h`](https://technet.microsoft.com/en-us/library/hh847753.aspx) would contain the command history for easy viewing. – Matt Jun 24 '15 at 00:38
  • Hi - thanks for the ideas. - I'm trying to stream the stdout one character at a time. Trying to avoid full page views... – Danny Jun 24 '15 at 00:43
  • @Teepeemm already mentioned it, `out-file` could be of some help. – JensG Jun 24 '15 at 00:55

1 Answers1

2

By no means perfect but I am just playing here for fun trying to appease your odd but curious to me need

function get-easyview{

    param([int]$Milliseconds= 50)
    $text = $input | Out-String 

    [char[]]$text | ForEach-Object{
        Write-Host -NoNewline $_
        # Only break for a non-whitespace character.
        if($_ -notmatch "\s"){Sleep -Milliseconds $Milliseconds}
    }
}

Get-ChildItem | get-easyview -Milliseconds 50

This will take the input object and convert it into a single string that will then be case as a char array. Then it will painfully display a single character at a time with a gap of X Milliseconds between characters. I wanted to shoot myself in the face using seconds. I hear a typewriter in my head watching this. Note: This only outputs to the host console and not the standard output stream. This would have to be the last pipe command. There is no usable -passthru with this.

Can't find the reference but PowerShell can only go so slow. I don't think I could get the sleep between 1-20 milliseconds with a noticeable difference. I'm probably wrong with the numbers but it is a thing.

The output is not exactly as it is on screen. I'm working on it.

Don't you forget about More

Or the PowerShell equivalent out-host -paging. Using Enter you can "absorb" the information at your own pace. Read more from this answer

Get-EasyView 2.0

I was playing more and I though about setting a switch so that you could go by character or line using some simple parameteres.

function get-easyview{

    param(
        [int]$Milliseconds= 50,
        [ValidateSet("Line","Character")] 
        [String] 
        $Pace = "Character"
    )

    If($pace -eq "Character"){
        $text = [char[]]($input | Out-String)
        $parameters = @{NoNewline = $true}
    } Else {
        $text = ($input | out-string) -split "`r`n"
        $parameters = @{NoNewline = $false}
    }

    $text | ForEach-Object{
        Write-Host $_ @parameters
        if($_ -notmatch "^\s+$"){Sleep -Milliseconds $Milliseconds}
    }
}

So now you can do calls like this

Get-ChildItem | get-easyview -Milliseconds 50
Get-ChildItem | get-easyview -Milliseconds 1000 -Pace Line
Get-ChildItem | get-easyview -Milliseconds 50 -Pace Character
Community
  • 1
  • 1
Matt
  • 45,022
  • 8
  • 78
  • 119
  • @user3430152 If it is any consolation: I love me too! I also added another update and fixed a small flaw in my first code. I had made a variable for milliseconds but didnt actually use it. – Matt Jun 24 '15 at 01:28