kali Posted May 26, 2016 Author Share Posted May 26, 2016 On 5/25/2016 at 4:32 PM, jaclaz said: Hmmm, the batch you posted seemingly mixes liberally HH , MM, SS and hs, you will have a number of incorrect results in many cases. And - if I get this right now - what you want is that the thingy shows time elapsed since start of the program updating it in "real time", i.e. something more like a "progress bar". jaclaz You are right. My batch can show incorrect results in many cases. If you fix my time subtraction batch into HH:MM:SS:hs Format It will be also very useful to me. An exactly you said. My want is time elapsed. Finally I tested your batch with wait.exe. It shows a continuous Elapsed process. I'm learner of batch. So I didn't understand the batch you posted. Thanks. Link to comment Share on other sites More sharing options...
jaclaz Posted May 26, 2016 Share Posted May 26, 2016 (edited) Yep , but you also failed to read the given link or the comment about the need of 0x08 hex characters (backspaces) in the batch (they cannot be posted), everyone has been (before or later) a newbie at batch scripting (or at something else), but in order to learn one needs to try and solve problems. What would you learn if I fix your time subtraction batch? Maybe you would learn more if you read and understand my time subtraction batch. (it is written in a very "linear" fashion and should be very easy to follow) Anyway the posted snippet has at least one more issue, using TASKLIST to monitor the running program *somehow* makes the line flash AND there is anyway an (intentional) typo in the (just to see if readers are paying attention ) in the :to_hs subroutine. And in the meantime I found a clever way to create the 0x08's "on the fly", so here is an updated little batch. Still you will need to find the typo in the math subroutine. So here it is: Spoiler @ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION ::This fills the BS and BS10 variable with 1 and 10 BackSpaces 0x08 chars FOR /F "tokens=1 delims=# " %%a IN ('"prompt #$H&echo on&for %%b in (1) do rem"') DO ( SET "BS=%%a" SET "BS10=%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a" ) SET Before=%Time% CALL :to_hs Before ECHO Time is now %Time% ECHO Starting program ... start /min cmd.exe /c wait.exe 10>nul :loop SET Now=%Time% CALL :to_hs Now SET /A DeltahsVal=%NOWhsval%-%BEFOREhsVal% CALL :to_HHMMShs Delta ::There are 11 0x08 characters in the line below between = and Elapsed <nul (set /p output=%BS10%%BS%Elapsed %Delta%) ::This updates the display roughly every second ping -n 1 127.0.0.1>nul TASKLIST |FIND /I "wait.exe">nul&&GOTO :loop ECHO Time is now %Time% ECHO Finished in %Delta% GOTO :EOF :to_hs SET %1HH=1!%1:~0,2! SET %1MM=1!%1:~3,2! SET %1SS=1!%1:~6,2! SET %1hs=1!%1:~9,2! SET /A %1hsVal=(!%1HH!-100)*360000+(!%1MM!-100)*6000+(!%1SS!-100)*100+(!%1SS!-100) GOTO :EOF :to_HHMMShs SET /A %1HH=!%1hsVal!/360000 SET /A %1MM=(!%1hsVal!-!%1HH!*360000)/6000 SET /A %1SS=(!%1hsVal!-!%1HH!*360000-!%1MM!*6000)/100 SET %1hs=0!%1hsVal:~-2! SET %1HH=0!%1HH! SET %1MM=0!%1MM! SET %1SS=0!%1SS! SET %1=!%1HH:~-2!.!%1MM:~-2!.!%1SS:~-2!,!%1hs:~-2! I have a couple "better" batches, but I will post them only once you will have had time to test the above and fix the small mis-calculation. jaclaz Edited May 26, 2016 by jaclaz Link to comment Share on other sites More sharing options...
kali Posted May 28, 2016 Author Share Posted May 28, 2016 On 5/26/2016 at 9:08 PM, jaclaz said: Yep , but you also failed to read the given link or the comment about the need of 0x08 hex characters (backspaces) in the batch (they cannot be posted), everyone has been (before or later) a newbie at batch scripting (or at something else), but in order to learn one needs to try and solve problems. What would you learn if I fix your time subtraction batch? Maybe you would learn more if you read and understand my time subtraction batch. (it is written in a very "linear" fashion and should be very easy to follow) Anyway the posted snippet has at least one more issue, using TASKLIST to monitor the running program *somehow* makes the line flash AND there is anyway an (intentional) typo in the (just to see if readers are paying attention ) in the :to_hs subroutine. And in the meantime I found a clever way to create the 0x08's "on the fly", so here is an updated little batch. Still you will need to find the typo in the math subroutine. jaclaz Sorry for late. I read the stackoverflow link you given above. It was about like progressbar. Last two days I explored many sites and learned many things. I'm very interested to learn batch scripting. I read and practice also. But some time I can't understand complicated script as newbie. For example in your script "prompt #$H&echo on&for %%b in (1) do rem" for 0x08 hex characters (you mentioned), to_hs as well as to_HHMMShs section. You set DeltahsVal variable but I couldn't find it's usage in the script. Shamed to asked foolishly. Link to comment Share on other sites More sharing options...
jaclaz Posted May 28, 2016 Share Posted May 28, 2016 First is an (ab)use of the PROMPT command (this is "rare" or "advanced"), see: http://ss64.com/nt/prompt.htmlhttp://superuser.com/questions/82929/how-to-overwrite-the-same-line-in-command-output-from-batch-file Second is due to expansion of parameter %1 (first parameter) in the CALLed subroutine (this is instead pretty much "common" or "simple"). When the batch CALLs the :to_HHMMShs subroutine as: CALL :to_HHMMShs Delta The "Delta" becomes %1 (and viceversa) so what will be executed will be: SET /A DeltaHH=!DeltahsVal!/360000 SET /A DeltaMM=(!DeltahsVal!-!DeltaHH!*360000)/6000 SET /A DeltaSS=(!DeltahsVal!-!DeltaHH!*360000-!DeltaMM!*6000)/100 SET Deltahs=0!DeltahsVal:~-2! SET DeltaHH=0!DeltaHH! SET DeltaMM=0!DeltaMM! SET DeltaSS=0!DeltaSS! SET Delta=!DeltaHH:~-2!.!DeltaMM:~-2!.!DeltaSS:~-2!,!Deltahs:~-2! jaclaz Link to comment Share on other sites More sharing options...
kali Posted May 29, 2016 Author Share Posted May 29, 2016 23 hours ago, jaclaz said: First is an (ab)use of the PROMPT command (this is "rare" or "advanced"), see: http://ss64.com/nt/prompt.htmlhttp://superuser.com/questions/82929/how-to-overwrite-the-same-line-in-command-output-from-batch-file Second is due to expansion of parameter %1 (first parameter) in the CALLed subroutine (this is instead pretty much "common" or "simple"). When the batch CALLs the :to_HHMMShs subroutine as: CALL :to_HHMMShs Delta The "Delta" becomes %1 (and viceversa) so what will be executed will be: jaclaz Thanks jaclaz. Very useful link. In the mean time I wrote a script. Your clues and links helped me to write this script. I got digital clock instead of Stop watch here. Hope your advice. Spoiler @echo off setlocal delayexpansion mode con cols=70 lines=15 title Setup Office 2010 pushd %~dp0 start "" wordpad.exe & goto time :time cls echo. echo. echo. Please Wait... echo. Installing MS Office 2010. It might be finished at %time% TASKLIST |FIND /I "wordpad.exe" > nul IF %ERRORLEVEL% EQU 1 goto exit ping -n 2 0.0.0.0 >nul cls goto :time :exit cls mode con cols=30 lines=10 echo. echo. echo. echo. echo. Installation Completed. ping -n 5 0.0.0.0 >nul exit /b Link to comment Share on other sites More sharing options...
jaclaz Posted May 30, 2016 Share Posted May 30, 2016 Yep , but you used the (common) CLS and re-drawing whole screen, and you are actually giving the user a totally false "estimation" of the time left, you are actually continuously showing the current time, if the "real" program actually takes 5 minutes to execute and terminate, you will have the user receive roughly 5*60/2=150 false informations It would IMHO be more logical to time once the actual time it takes on an "average" machine, add to it (say) a 20% increase, so that the user will have something like: Time is now 11.47.16 Starting program ... Expected time 360 seconds Executed in 305 seconds. <-line that continuously updates "Elapsed time" Time is now 11.50.21 And will have additionally the "good feeling" that his/her machine is faster than expected (still false, BTW). Find attached a couple "almost finished" batches showing the "time elapsed". First one uses a time format, the second uses "plain" seconds (and is thus simplified). The posted ones use WMIC instead of TASKLIST as this (strangely) avoids the flashing (or viceversa strangely TASKLIST induces the flashing of the line). jaclaz time_exe.zip Link to comment Share on other sites More sharing options...
jumper Posted May 31, 2016 Share Posted May 31, 2016 To time a DOS app: echo.|time app.exe echo.|time If the app will clear the screen/console, redirect the time to a file: echo.|time>start.txt app.exe more start.txt echo.|time Link to comment Share on other sites More sharing options...
kali Posted May 31, 2016 Author Share Posted May 31, 2016 On 5/30/2016 at 3:56 PM, jaclaz said: jaclaz time_exe.zip Very nice script, Just awesome. It's (time_exe) working like that what I wanted. Thanks a lot jaclaz. Link to comment Share on other sites More sharing options...
jaclaz Posted May 31, 2016 Share Posted May 31, 2016 58 minutes ago, kali said: Very nice script, Just awesome. It's (time_exe) working like that what I wanted. Thanks a lot jaclaz. You are welcome , though you will notice that the processor will get roughly 50% usage just by running the batch . jaclaz Link to comment Share on other sites More sharing options...
kali Posted June 1, 2016 Author Share Posted June 1, 2016 23 hours ago, jaclaz said: You are welcome , though you will notice that the processor will get roughly 50% usage just by running the batch . jaclaz processor will get roughly 50% usage- I'll analysis this. I'm a hardware troubleshooter. To save time I use 90% of my software silent install. Just I wanted to add something new in my silent script like this. It's awesome. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now