0

i want to make such as loading indicator just like : installation is running... and those dots should be appear progressively and once they are three their number should be reinitialized to one dot and all happens in the same line.

for this i've tried to mix code of two small scripts : the first plays continuestly the dots and the seconds makes a counter increase its value by echoing it in the same line.

at the end i got this code which is the closest solution for what i want to achieve but still with a problem which is that when there are already three dots, the next row which has less number of dots will overwrite its similar part from the previous one but the remaining part from the previous row will stay so at the end it looks like there are always three dots and all will looks like just a simple static echoed text..

here is the code :

@echo off
cls
setlocal EnableDelayedExpansion EnableExtensions


call :CreateCR
:spinner
set mSpinner=%mSpinner%.

if %mSpinner%'==.................................' (
    set mSpinner=.


)       
        :: Wait one second.
        ping 127.0.0.1 -n 2 >nul

        set /P "=Installation Java en cours%mSpinner%!CR!" <nul


::set /p "=Installation Java en cours" <nul
::echo %mSpinner%

goto spinner


:exit
::echo(
goto :eof

:CreateCR
rem setlocal EnableDelayedExpansion EnableExtensions
set "X=."
for /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!

echo !X!  > %temp%\cr.tmp
echo\>> %temp%\cr.tmp
for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do (
   endlocal
   set cr=%%a
   goto :eof
)
goto :eof
Community
  • 1
  • 1
Bardelman
  • 2,176
  • 7
  • 43
  • 70
  • 1
    just a site note, when you run commands which print percentage the console "ConEmu" will actually make a graphical progress bar out of it.https://code.google.com/p/conemu-maximus5/wiki/Progress – eckes Jan 03 '15 at 19:00
  • I believe it can be done, but I'd refer you to this link https://wpdev.uservoice.com/forums/266908-command-prompt/category/87960-cmd with specific reference to the suggestions about adding `spinner` and `ecko` to W10... – Magoo Jan 03 '15 at 19:08

2 Answers2

0

You can capture a backspace character to a variable like this (courtesy of dbenham):

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

Then to erase your dots, simply send a number of

<NUL set /P "=%BS%"

... one %BS% for each dot you want to erase. As an alternative, you could use a spinner that spins instead of dots that grow. See this question and answer. In the answer there, insert the for /f line above to capture the backspace to %BS% at the top of the script, and replace all occurrences of ^H with %BS% in the spinner strings at the bottom.

Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
  • Thanks for your answer, i ll try it, just your last link is refering to this same question. Please give me the right one :) – Bardelman Jan 03 '15 at 19:20
  • @Bardelman Sorry about that. Edited and fixed. Just in case you don't know, that ` – rojo Jan 03 '15 at 19:32
  • i made this change in the if statement : if %mSpinner%'==.....' ( set mSpinner=. for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a" > nul – Bardelman Jan 04 '15 at 09:13
0

A more simplistic approach would be the following:

@echo off
:spinner
set mSpinner=%mSpinner%.
if %mSpinner%'==....' (set mSpinner=.)
cls
echo Installation in progress%mSpinner%
ping 127.0.0.1 -n 2 >nul
goto spinner