Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Win/Batch: display progress of work  (Read 16427 times)

0 Members and 1 Guest are viewing this topic.

lwkt

    Topic Starter


    Rookie

    Win/Batch: display progress of work
    « on: August 26, 2009, 10:04:49 PM »
    Hi there,

    I am using batch file to collect files generated by other application.

    The elapse time of the collection process may take for 10 to 30 minutes depends
    on the number of files generated.

    I have told users to wait for the completion of process with following echo commands: -

    ===================================================

    ECHO Collecting information... Please be patient...
    ECHO.
    ECHO Will take 10 to 30 minutes...

    ===================================================

    Is it possible to display some work in progress message or
    putting a continuous ...... sign on the screen during the running of collection process?

    Thanks,
    Thomas

    smeezekitty

    • Guest
    Re: Win/Batch: display progress of work
    « Reply #1 on: August 26, 2009, 10:20:17 PM »
    not without seeing your batch code

    lwkt

      Topic Starter


      Rookie

      Re: Win/Batch: display progress of work
      « Reply #2 on: August 26, 2009, 11:26:57 PM »
      Here is the code:

      ============================================
      @ECHO OFF.
      EXTRACT.exe "File *.txt" > "date_time*.txt"
      rem
      ECHO Collecting information... Please be patient...
      ECHO.
      ECHO Will take 10 to 30 minutes...
      rem
      pause
      exit
      ===============================================

      Please be noted that EXTRACT.exe is an
      executable that use to collect required information
      and translate to text files. It is come with a
      proprietary application.

      Thanks,
      Thomas

      smeezekitty

      • Guest
      Re: Win/Batch: display progress of work
      « Reply #3 on: August 26, 2009, 11:33:41 PM »
      since the program is operating in the background
      i dont think you can show progress
      the best you can do is this have a spinning indicator like this
      | then / then -- then \
      even that would be hard
      maybe salmon_trout aka virus accuser or batch file basics may help

      lwkt

        Topic Starter


        Rookie

        Re: Win/Batch: display progress of work
        « Reply #4 on: August 27, 2009, 12:11:05 AM »
        Sorry, it is a foreground process.
        The correct code is: -

        ============================================
        @ECHO OFF.

        ECHO Collecting information... Please be patient...
        ECHO.
        ECHO Will take 10 to 30 minutes...
        rem
        EXTRACT.exe "File *.txt" > "date_time*.txt"
        rem
        pause
        exit
        ===============================================

        Spinning indicator is fine. At least it shows
        the collection process is still running.

        Thanks,
        Thomas

        BatchFileBasics



          Hopeful

          Thanked: 18
          Re: Win/Batch: display progress of work
          « Reply #5 on: August 27, 2009, 12:16:48 AM »
          it should be pretty straight forward.
          it would help if some one could extend my knowledge of making multi line variables...
          "%var%" = Hello
                         there

          but this is what i got so far
          Code: [Select]
          @echo off
          set msgg=Collecting information... Please be patient...
          set dly=Ping localhost -n 2 -w 1000 ^>nul ^& cls
          EXTRACT.exe "File *.txt" > "date_time*.txt"
          :wait
          %dly%
          echo %msgg% \
          %dly%
          echo %msgg% ^|
          %dly%
          echo %msgg% /
          %dly%
          echo %msgg% -
          goto wait

          OOPS
          new change of code, forgot most important piece "EXTRACT.exe "File *.txt" > "date_time*.txt""
          When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

          Salmon Trout

          • Guest
          Re: Win/Batch: display progress of work
          « Reply #6 on: August 27, 2009, 12:25:17 AM »
          Instead of passing a wildcard to Extract.exe and leaving it to finish, can't you pass every single file name you want it to process, one by one? If you counted them first, you could show a done/to do figure e.g. 1/127, then 2/127 then 3/127 etc (Or calculate percentage done)



          BatchFileBasics



            Hopeful

            Thanked: 18
            Re: Win/Batch: display progress of work
            « Reply #7 on: August 27, 2009, 12:27:30 AM »
            great idea  ;)

            sadly i must continue this is the morning
            When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

            smeezekitty

            • Guest
            Re: Win/Batch: display progress of work
            « Reply #8 on: August 27, 2009, 12:45:56 AM »
            try this
            Code: [Select]
            echo off
            cls
            set /A files=0
            echo please wait a few min
            for %%f in (*.txt) do set /A files=%%files+1
            set /A _done=0
            for %%x in (*.txt) do (
            cls
            EXTRACT.exe "File %%x" > "date_time%%x.txt"
            echo %%_done of %%files done
            set /A _done = %%_done+1
            )

            Salmon Trout

            • Guest
            Re: Win/Batch: display progress of work
            « Reply #9 on: August 27, 2009, 01:03:41 AM »
            smeezekitty, a reasonable first effort.  But. you are getting ordinary %variables% and single letter loop variables confused. What kind of animal is %%files? And a bit of delayed expansion is needed too. Maybe you could try the script out on some dummy files before posting?







            smeezekitty

            • Guest
            Re: Win/Batch: display progress of work
            « Reply #10 on: August 27, 2009, 01:26:43 AM »
            i tired it
            and it printed the variable name instead of printing there value
            why is that?
            it should have worked

            smeezekitty

            • Guest
            Re: Win/Batch: display progress of work
            « Reply #11 on: August 27, 2009, 01:35:48 AM »
            ok i think i got it figured out it seemed to work but i am not completely sure
            Code: [Select]
            echo off
            cls
            set /A files=0
            echo please wait a few min
            for %%f in (*.txt) do set /A files=%files%+1
            set /A _done=0
            for %%x in (*.txt) do (
            cls
            echo %_done% of %files% done
            set /A _done=%_done%+1
            EXTRACT.exe "File %%x" > "date_time%%x.txt"
            )

            lwkt

              Topic Starter


              Rookie

              Re: Win/Batch: display progress of work
              « Reply #12 on: August 27, 2009, 09:12:05 AM »
              Thank you for your suggestions.

              However, the number of files that Extract.exe would be generated were not constant.
              The suggestions from Salmon and Smeezekitty are not fit for my case.

              BatchFileBasics' suggestion sound interesting but the code
              just putting my program into endless loop of spinning
              indicator.  Any idea about the problem?

              Thanks,
              Thomas

              smeezekitty

              • Guest
              Re: Win/Batch: display progress of work
              « Reply #13 on: August 27, 2009, 11:49:29 AM »
              no
              it should work
              because it counts the files in the directory before it runs extract
              meaning you could have 1 10 or 1000 files it would still work fine

              lwkt

                Topic Starter


                Rookie

                Re: Win/Batch: display progress of work
                « Reply #14 on: August 27, 2009, 05:46:54 PM »
                Smeezekitty,

                Your code works perfect if we know the total number of files in the directory.

                However,  the function of  Extract.exe is to extract data from some anolog logging devices and then convert to text files. The amount of files generated depends on the data that collected before the requested period.
                Therefore, the number of files in the collected folder is unknown before Extract.exe is being run.

                My purpose of using progress indicator is to indicate that process of collection and data convertion is still running. Telling user to be patient.

                Thanks,
                Thomas

                smeezekitty

                • Guest
                Re: Win/Batch: display progress of work
                « Reply #15 on: August 27, 2009, 05:49:55 PM »
                for %%f in (*.txt) do set /A files=%files%+1
                this line is suppose to count the files before it starts
                but i think i may know what you mean
                and without the source code of extract.exe an a C compiler
                i dont think waht you are asking for is possable

                lwkt

                  Topic Starter


                  Rookie

                  Re: Win/Batch: display progress of work
                  « Reply #16 on: August 28, 2009, 12:11:39 AM »
                  Well, I have another idea.

                  At first I created a batch file that make use of BatchFileBasics' code.(say indicator.bat).

                  Then before I start to run Extract.exe, I spawn  a child process with separate DOS window and execute indicator.bat.
                  (The command may be START indicator.bat ... etc. Please suggest.)

                  When Extract.exe is finished, close the child process window.

                  Here is my program flow (the pseudo code portion still need to further elaborate into corresponding DOS commands): -

                  @echo off
                  REM
                  <pseudo code> spawn child window to run indicator.bat
                  REM
                  EXTRACT.exe "File *.txt" > "date_time*.txt"
                  REM
                  <pseudeo code> minimize main program DOS comand window
                  REM
                  REM After finish run of EXTRACT.exe
                  <pseudo code> close the child process
                  <pseudo code> restore the main program DOS command window
                  REM
                  ECHO done.
                  pause
                  exit

                  Is that feasible?

                  Salmon Trout

                  • Guest
                  Re: Win/Batch: display progress of work
                  « Reply #17 on: August 28, 2009, 02:21:18 AM »
                  Rewrite extract.exe

                  lwkt

                    Topic Starter


                    Rookie

                    Re: Win/Batch: display progress of work
                    « Reply #18 on: August 28, 2009, 04:22:46 AM »
                    EXTRACT.exe come from an proprietary application, it is impossible to rewrite.

                    BTW, I think the new approach seems make sense, I know the way to start
                    a separate window to show the spinning indicator. The command is
                    "START indicator.bat".

                    But, I don't know how to stop that process after the completion of EXTRACT.exe
                    in main window.

                    Anyway, I just want to provide an indication to some inexperience users during the execution of the application. If no solution in Win/Batch, just let it be.

                    Thanks,
                    Thomas


                    lwkt

                      Topic Starter


                      Rookie

                      Re: Win/Batch: display progress of work
                      « Reply #19 on: August 28, 2009, 08:15:16 AM »
                      Just found that DOS command TASKKILL can kill process or application.

                      However, it seems that TASKKILL can only kill program that in .exe format.
                      That means I have to convert the indicator.bat file to indicator.exe then
                      spawn the program in the main DOS window.

                      When the collection process is finished. I can use the TASKKILL to kill
                      the indicator process.

                      Does this approach feasible?


                      smeezekitty

                      • Guest
                      Re: Win/Batch: display progress of work
                      « Reply #20 on: August 28, 2009, 12:13:00 PM »
                      write a C program to do it

                      Salmon Trout

                      • Guest
                      Re: Win/Batch: display progress of work
                      « Reply #21 on: August 28, 2009, 12:57:54 PM »
                      write a C program to do it


                      I guess you would be an expert in the D programming language.

                      Salmon Trout

                      • Guest
                      Re: Win/Batch: display progress of work
                      « Reply #22 on: August 28, 2009, 03:48:37 PM »
                      [Moderated Message: Removed Post. Please keep it clean.]
                      « Last Edit: August 28, 2009, 09:30:16 PM by Carbon Dudeoxide »

                      Helpmeh



                        Guru

                      • Roar.
                      • Thanked: 123
                        • Yes
                        • Yes
                      • Computer: Specs
                      • Experience: Familiar
                      • OS: Windows 8
                      Re: Win/Batch: display progress of work
                      « Reply #23 on: August 28, 2009, 08:05:52 PM »
                      ...
                      Taskkill cmd will work, but it will close all cmd.exe windows.
                      Where's MagicSpeed?
                      Quote from: 'matt'
                      He's playing a game called IRL. Great graphics, *censored* gameplay.

                      wbrost



                        Intermediate
                      • Thanked: 11
                        Re: Win/Batch: display progress of work
                        « Reply #24 on: August 31, 2009, 07:10:26 AM »
                        ...
                        Taskkill cmd will work, but it will close all cmd.exe windows.

                        this is true except if you use the PID of the process you are trying to kill. If you know the PID then you can just stop the specific process.

                        lwkt

                          Topic Starter


                          Rookie

                          Re: Win/Batch: display progress of work
                          « Reply #25 on: August 31, 2009, 06:56:26 PM »
                          The process I want to kill was spawn from a parent process. PID of the child process will change on each run of the parent process.

                          Is it possible to know the PID of a spawn process?




                          billrich

                          • Guest
                          Re: Win/Batch: display progress of work
                          « Reply #26 on: August 31, 2009, 08:19:55 PM »
                          Tasklist will list the pid of all processes:


                          C:\>tasklist

                          Image Name                   PID
                          ============== ======
                          System Idle Process            0
                          System                         4
                          smss.exe                     764
                          csrss.exe                   1112
                          winlogon.exe                1284
                          services.exe                1452
                          lsass.exe                   1512
                          svchost.exe                  572
                          svchost.exe                 1256

                          If each child has unique name, use findstr and then taskkill to kill number in second field.

                          good luck
                          « Last Edit: August 31, 2009, 08:47:08 PM by billrich »

                          lwkt

                            Topic Starter


                            Rookie

                            Re: Win/Batch: display progress of work
                            « Reply #27 on: September 01, 2009, 04:32:12 AM »
                            It is not possible to use PID as PID of the child process
                            sometimes is smaller and sometimes is larger than the
                            PID of the main program.

                            As checked from the help menu of taskkill, there is a
                            option of "windowtitle".

                            Therefore I tried to test with following code:

                            main program: -
                            @echo off
                            start "counter" counter.bat
                            :end
                            pause
                            exit

                            Child process (counter.bat): -
                            @echo off
                            set msgg=Collecting information... Please be patient...
                            set dly=Ping localhost -n 2 -w 1000 ^>nul ^& cls
                            :wait
                            %dly%
                            echo %msgg% \
                            %dly%
                            echo %msgg% ^|
                            %dly%
                            echo %msgg% /
                            %dly%
                            echo %msgg% -
                            goto wait
                            :end

                            When the child process was running in a CMD window with
                            title of "counter - counter.bat"

                            I issue the following command kill the child task:
                            D:/taskkill /fi "windowtitle eq counter - counter.bat" /im cmd.exe

                            It can kill the child process!!
                            Well, I think I can use this approach to display the progress of work.

                            O.K. Does anyone know the way to minimize the main program when the
                            child process is running and then resume the main program after the child process was being killed?


                            billrich

                            • Guest
                            Re: Win/Batch: display progress of work
                            « Reply #28 on: September 01, 2009, 04:55:43 AM »
                            When you call the Child killer from the main batch, an exit /B  will return control back to the main batch.   An exit by itself will return control to windows.

                            Quote
                            <<<<"
                            Microsoft Windows XP [Version 5.1.2600]
                            (C) Copyright 1985-2001 Microsoft Corp.

                            C:\>exit  /?
                            Quits the CMD.EXE program (command interpreter) or the current batch
                            script.

                            EXIT [/B] [exitCode]

                              /B          specifies to exit the current batch script instead of
                                          CMD.EXE.  If executed from outside a batch script, it
                                          will quit CMD.EXE

                              exitCode    specifies a numeric number.  if /B is specified, sets
                                          ERRORLEVEL that number.  If quitting CMD.EXE, sets the process
                                          exit code with that number
                            .

                            C:\>

                            lwkt

                              Topic Starter


                              Rookie

                              Re: Win/Batch: display progress of work
                              « Reply #29 on: September 01, 2009, 07:00:16 AM »
                              Well what I mean is the <pseudo code> portion (highlighted in red) that I had posted previously.
                              ==========================================
                              @echo off
                              REM
                              <pseudo code> spawn child window to run indicator.bat
                              REM
                              EXTRACT.exe "File *.txt" > "date_time*.txt"
                              REM
                              <pseudeo code> minimize main program DOS comand window
                              REM
                              REM After finish run of EXTRACT.exe
                              <pseudo code> close the child process
                              <pseudo code> restore the main program DOS command window
                              REM
                              ECHO done.
                              pause
                              exit
                              ==================================================