| 1. |
Solve : Win/Batch: display progress of work? |
|
Answer» for %%f in (*.txt) do set /A files=%files%+1 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 ... 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 <<<<". 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 ================================================== |
|