2

i just wrote an extremely long script that takes a list of URLs and runs a series of API calls, processes them etc.

Unfortunately for majority of the calls, response is empty (to give scale, i get result for ~100 / 4000 urls )

I'm wondering if there is a way to show in terminal (or powershell) some kind of animation to indicate that the process is still running. Currently - i have the standard blinking underscore.

I was thinking of something like alterating between \ - / |

i definitely don't want to trash the console with printing too much.

does anyone know if something like that is possible ?

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
wickedpanda
  • 51
  • 1
  • 8
  • Does this answer your question? [Python Progress Bar](https://stackoverflow.com/questions/3160699/python-progress-bar) –  May 16 '22 at 12:35
  • the simplest solution is to just display a counter. [*grin*] something like `13 of 666` works well and tends to be fairly fast. the built in PoSh `Write-Progress` cmdlet, tho, is notoriously S_L_O_W. it is the 1st thing one recommends _disabling_ when a script is reported to be "too dang slow". – Lee_Dailey May 16 '22 at 12:39
  • issue is - i don't know how many iterations there will be :) Depending on a user input - there might be one domain to take the links form, or might be a hundred, In each of those domains you can find either a sitemap( containing URLs), a sitemap index ( containing a couple sitemaps) or nothing at all. Than those all links get processed. As only successful calls are reported - for majority of time, the idle looks stuck :) So i look for somethign to show the user that their idle didn't crash :) Unfortunately simple counter as i usually do that - won't do :( – wickedpanda May 16 '22 at 17:55

1 Answers1

0

This is one way you can do it in PowerShell.

$progress = '\', '|', '/', '-'
$i = 0
[console]::Write('Doing something...')
while($true) {
    $char = $progress[$i++ % $progress.Count]
    [console]::Write("$char$([char]0x8)")
    Start-Sleep -Milliseconds 300
}

Relevant docs:

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37