question

AleMadama-9897 avatar image
0 Votes"
AleMadama-9897 asked AleMadama-9897 commented

powershell script: progress bar infinite loop, until key pressed

Hi all,
I would have to create a script (powershell or DOS) doing this:

a wording printed (e.g. "debug in progress:") and beside a progress bar (dots increasing....)
when the dots reach number of 100, they start from 1 dot (still beside the same wording):

debug in progress:...........................

this in an infinite loop, until I press a key


is it possible?
thanks!




windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered AleMadama-9897 commented

Hi,

You can try something like this.

 $notpressed = $true
 $string = 'debug in progress:'
 $dots = 100
 $i = 0
 while($notpressed){
     $i++
     if([console]::KeyAvailable)
     {
         $notpressed = $false    
     }    
     else{
         if($i%($dots+1) -eq 1)
         {
             Write-Host $string -NoNewline
             Start-Sleep -Milliseconds 500          
         }
         elseif($i%($dots+1) -eq 0)
         {
             Write-Host '.'
             Start-Sleep -Milliseconds 500           
         }
         else{
             Write-Host '.' -NoNewline
             Start-Sleep -Milliseconds 500           
         }
     }
 }

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

many thanks Ian!

excellent! I owe you a wagon of beers!

do you think it would be possible write also in a DOS script or maybe that language does not allow this?

thanks! thanks! thanks!

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered AleMadama-9897 commented

Yes, it is. Is this a homework assignment?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

:)

nope...only I would need something like this to insert into a bigger script
but I didn't know how to do it...

;)

0 Votes 0 ·