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 16424 times)

0 Members and 1 Guest are viewing this topic.

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
                ==================================================