1.

Solve : Win/Batch: display progress of work?

Answer»

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 possableWell, 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
spawn child window to run indicator.bat
REM
EXTRACT.exe "File *.txt" > "date_time*.txt"
REM
minimize main program DOS comand window
REM
REM After finish run of EXTRACT.exe
close the child process
restore the main program DOS command window
REM
ECHO done.
pause
exit

Is that feasible?
Rewrite extract.exe
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

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?

write a C program to do it
Quote from: smeezekitty on August 28, 2009, 12:13:00 PM

write a C program to do it


I guess you would be an expert in the D programming language. [Moderated Message: Removed Post. Please keep it CLEAN.]...
Taskkill cmd will work, but it will close all cmd.exe windows. Quote from: Helpmeh on August 28, 2009, 08:05:52 PM
...
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.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?



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 luckIt 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?

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:\>Well what I mean is the 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
==================================================



Discussion

No Comment Found