Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Controlling PowerShell's console output

$
0
0

How do you control PowerShell's console output and overwrite the last character written?

I want to overwrite a character with a loop, like the spinning baton in UNIX while some Job.status -eq running. You know like cycle through |/-\| so it looks like a spinning bar.

 

I have the loop written but the console never seems to want to overwrite the last chacter. I am using write-host -nonewline, so at least I'm on the right line.

 

I have tried using `b and then the write-host, but it actually get this box character written to the screen instead of a backspace.

 

I have tried using [console]::cursor stuff but I can't set the cursor to less than zero and zero just leaves the cursor where it was anyway.

 

I also tried using [string]::format and {0,1} type stuff, but it always writes next to the last character. There's a guy who wrote a countdown timer, and when I run his code it doesn't work for me (http://poshtips.com/2010/03/29/powershell-countdown-timer/). The timer just keeps writing to the side after 40 whitespaces.

 

The only way I have been able to do it is by calling cls before each character; of course i'd rather not clear the entire screen.

 

I'm hoping you will enlighten me...


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>