Jump to content

For /f with Progress Bar


Recommended Posts

Hello everyone, I would like to support to improve a batch script.
My script is basically a loop-FOR as below and would like to add a progress bar.
I researched a lot about progress bars, but basically all use a loop-FOR in the other and my script is use For-loop Too. I do not know how to put my loop within the progress bar examples

Note: Sorry for my english
following examples

-------------------------------------------
@ECHO OFF
FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO DISM /online /add-package /packagepath:%%F /quiet /norestart
eCHO finished
PAUSE >NUL
----------------------------------------------

Would like add only status bar in my script

Thank you in advance

Stenio L

bar.png

Link to comment
Share on other sites


Basically that would be:

 

@ECHO OFF
FOR /F "TOKENS=*" %%F IN (Patchs.TXT) DO (
DISM /online /add-package /packagepath:%%F /quiet /norestart
CALL :_update_statusbar
)
eCHO finished
PAUSE >NUL
GOTO :EOF
:_update_statusbar
REM Put here whatever statusbar update command
GOTO :EOF

But which "status bar" are you talking about?

The generic issue with status bars or similar is that there is no way to have them being "accurate", as you don't know how much time/how many items/etc. you are going to process, how many you already processed and how many will need to be processed.

Only seemingly unrelated, a recent thread:

jaclaz



 

Edited by jaclaz
Link to comment
Share on other sites

23 minutes ago, StenioL said:

Can you seen attached? I´m trying  mount this status bar.

Thanks a lot.

Attached WHERE? :dubbio:

In your original post there is an image, in your second post there is nothing.

How difficult is to post a link or at least name the program (or script or *whatever*) that creates that status bar?

jaclaz
 

Link to comment
Share on other sites

Yeah

In first post that image ..I want create this status bar in my script

The problem is:

I DON´T KNOW what error....Sorry...

Explain is...First place is Only to Elevate USER that run CMD ...Second place is Progress BAR

Error is about theses lines:

I use REM to test... the real command is   WUSA.EXE %%F /NORESTART /QUIET

-------------------------------

REM ECHO ABOVE IS 
echo %%F 
rem MY COMMAND´S IS HERE
REM WUSA.EXE %%F /norestart /quiet

-----------------------------------

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: BatchGotAdmin
::-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
::
rem @ECHO OFF
FOR /F "TOKENS=*" %%F IN ('dir /b *.msu') DO (

REM ECHO ABOVE IS 
echo %%F 
rem MY COMMAND´S IS HERE
REM WUSA.EXE %%F /norestart /quiet


CALL :_update_statusbar
)
:_update_statusbar
color 0f
set load=
set/a loadnum=0

:loading

set load=%load%Û
cls
ECHO.
ECHO.
ECHO.
ECHO  ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo  Û                                                                    Û
echo  Û                     Installation Progress                          Û
echo  Û     0    10   20   30   40   50   60   70   80   90   100          Û
echo  Û     ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´           Û
echo  Û     %load% 
echo  Û     %load% 
echo  Û                                                                    Û
echo  Û                                                                    Û
ECHO  ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ

timeout /t 1 >nul
set/a loadnum=%loadnum% +1
if %loadnum%==15 goto Done
goto loading
:Done
echo.
rem pause
rem *your action here*
rem pause
exit 
GOTO EOF
:EOF
 





Link to comment
Share on other sites

You CLEARLY copied that part from another script, and that is NOT a "status bar" it is a "fake" status bar, it only increments itself every 1 second or so using timeout /t 1.

This should work, but it will still (probably) suck big:

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
::Initialize Status bar
color 0f
set load=
set/a loadnum=0
:: BatchGotAdmin
....
....
FOR /F "TOKENS=*" %%F IN ('dir /b *.msu') DO (
REM ECHO ABOVE IS 
echo %%F
rem MY COMMAND´S IS HERE
REM WUSA.EXE %%F /norestart /quiet
CALL :_update_statusbar
)
ECHO Out of For loop
ECHO.
PAUSE >nul
GOTO :EOF

:_update_statusbar
set load=%load%Û
cls
ECHO.
ECHO.
ECHO.
ECHO  ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo  Û                                                                    Û
echo  Û                     Installation Progress                          Û
echo  Û     0    10   20   30   40   50   60   70   80   90   100          Û
echo  Û     ÃÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÅÄÄÄÄÄ´           Û
echo  Û     %load% 
echo  Û     %load% 
echo  Û
echo  Û                                                                    Û
ECHO  ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ
set/a loadnum+=1
if %loadnum%==52 SET /A loadnum=0&&SET load=
GOTO :EOF

jaclaz

Link to comment
Share on other sites

Many thanks for your support.
In fact I do not really know how to put together a decent script, I have the humility to recognize that. Scripts are rather a lot of pieces that in practice do not work. I will continue studying and researching for later able to develop a less bad code

I want to thank you immensely your support and patience.

StenioL

Link to comment
Share on other sites

Well, the point is still that having a progress bar (or similar) in batch is not really possible/smart (that is the essence of the thread I pointed you to, the "digital watch" there is equivalent to a progress bar), since essentially you are using an installer you might want to use an external program to show a "decent" progress bar, still (as in the given thread) it will be grossly approximated as you don't know how long will the actual install take.

As an example you can use the good ol' Wizard Apprentice:
http://wizapp.sourceforge.net/

it has a PB option that creates a progress bar:

http://wizapp.sourceforge.net/manual.html

jaclaz


 


 

Link to comment
Share on other sites

Beside the real challenge of having really clever progress bar (a progress bar should be based on the time needed to do the whole process but in most cases you can't predict it accurately) , i'll add that doing this kind of thing (progress bar) with autoit could be perhaps easier for a newbie.

Link to comment
Share on other sites

3 hours ago, allen2 said:

 i'll add that doing this kind of thing (progress bar) with autoit could be perhaps easier for a newbie.

... or any other scripting language, since it is an installation, I would rather use the NSIS (which is IMHO simpler than AutoIt):


http://nsis.sourceforge.net/Features

Anyway, attached  is a "decent" (IMHO) batch progress bar ;).

jaclaz

myprogbar.zip

Link to comment
Share on other sites

My preference is to forget about the fancy console window GUI progress bar and instead use the console window title bar to update the end user.

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion
Reg Query "HKU\S-1-5-19" 1>Nul 2>&1 || (PowerShell -ExecutionPolicy Bypass^
 -Command "SaPs -Verb RunAs -PSPath '%ComSpec%' -Args '/C """"%~f0""""'"
	Exit/B)
If /I "%CD%\" NEq "%~dp0" PushD %~dp0
Set "bar="
For /L %%a In (1,1,48) Do Set "bar=!bar!>"
Set "n=0"
For %%a In (*.msu) Do Set/A n+=1
Set "i=0"
Echo( Processing files:
For %%a In (*.msu) Do (
	Set/A i+=1, percent=i*100/n, barLen=48*percent/100
	For %%b In (!barLen!) Do Title !percent!%%  !bar:~,%%b!
	Echo( !i!- %%a
	WUSA.EXE "%%a" /norestart /quiet)
Title Press any key to exit . . .
Timeout -1 1>Nul

Hope this gives you a more sensible solution for your script.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...