| 1. |
Solve : Forcing wait-to-finish for each command in batch files? |
|
Answer» When running a batch file, each command does not seem to wait until a previous command has finished. Thanks wbrost,Start /wait commandORprogram Will wait for the command or program to terminate before continuing. I'm not 100% sure that it works for commands, it should though.Hi everyone... I'm a complete newbie to DOS...so please be gentle with technical terms... I use PDMS at work and DOS/bat files set everything up... The problem is I have a .bat file that fires up a simple PDMS .mac file... The .mac creates a text file.... Then the idea was the original .bat would RENAME/MOVE this text file... What I suspect is happening is that the .mac is creating the text file but my .bat file is carrying on and as there is no text file to RENAME/MOVE it's finishing... Is there a way to say to DOS check/keep checking that C:\text.txt has been fully built and ready to be renamed... I tried to use the suggestion on this post, see below :- C:\AVEVA\pdms11.6.SP1\pdms.bat TTY SEA SYSTEM/XXXXXX /TEST/DESIGN $m/c:\PDMS\Run_Dice.mac :loop ping -n 1 -w 3000 1.1.1.1 > nul if exist C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt ( echo DOCUMENT exists rename C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt KUPE-DICE-CHECK.txt MOVE C:\AVEVA\pdms11.6.SP1\pdmsuser\KUPE-DICE-CHECK.txt C:\PDMS\Results\Dice ) else ( echo document doesn't exist go to loop ) Cheers NeilTry "calling" the first batch file. Code: [Select]CALL C:\AVEVA\pdms11.6.SP1\pdms.bat TTY SEA SYSTEM/XXXXXX /TEST/DESIGN $m/c:\PDMS\Run_Dice.mac Cheers That worked great....the code is now continueing... The problem now is the code is continueing as I wanted...but by the time the code goes back to the .bat :- if exist C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt ( echo Document exists rename C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt KUPE-DICE-CHECK.txt The file is in existance...but it's still been compiled...so cannot be coppied yet... Is there a way to check the compiling is finished before it continues to the rename/move ? Cheers Neil you could check to see if the process is still active using tasklist. Code: [Select]tasklist /FI "imagename eq firefox.exe" change firefox.exe to the name of what you are looking for. If you need to know run the process and watch task manager.Hi...thanks for the reply...not sure if I've included it into my code correctly... But you are correct...when the adm.exe completes running then I want to carry on to the rest of the .bat code... See below how I've used it....please TELL me if it's correct...as it doesn't seem to be making any difference... -- -------- CALL C:\AVEVA\pdms11.6.SP1\pdms.bat TTY SEA SYSTEM/XXXXXX /TEST/DESIGN $m/c:\PDMS\Run_Dic.mac tasklist /F1 "imaginename eq adm.exe" rename C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt KUPE-DICE-CHECK.txt MOVE C:\AVEVA\pdms11.6.SP1\pdmsuser\KUPE-DICE-CHECK.txt C:\PDMS\Results\Dice -- -------- Cheers NeilQuote from: NEILD on September 04, 2009, 12:34:03 PM
first thing I see is that the command is /FI not /F1 second is the image name is incorrect it should be "imagename eq adm.exe" I will work on this and see if I can come up with something. There might be some one that already has an example for you to use. ok this will check and see if the process is still active and if not then stop for 15 seconds and try again. Code: [Select]@ECHO OFF :loop CLS set errorlevel= tasklist /fi "imagename eq adm.exe" | find /i "adm.exe"> NUL if /i %errorlevel% GTR 0 goto yes ECHO adm is working! PING -n 1 -w 15000 1.1.1.1 > nul GOTO loop :yes ECHO. ECHO. ECHO adm is finished pause wbrost thanks so much for helping me with this... I've added your changes to my .bat -- ------------- CALL C:\AVEVA\pdms11.6.SP1\pdms.bat TTY SEA SYSTEM/XXXXXX /TEST/DESIGN $m/c:\PDMS\Run_Dic.mac @ECHO OFF :loop CLS set errorlevel= DEL C:\AVEVA\pdms11.6.SP1\pdmsuser\temp.txt ..................$$$$ coding stops at this point $$$$............ tasklist /fi "imagename eq adm.exe" l find /i "adm.exe"> NUL DEL C:\AVEVA\pdms11.6.SP1\pdmsuser\temp1.txt if /i %errorlevel% GTR 0 goto yes DEL C:\AVEVA\pdms11.6.SP1\pdmsuser\temp2.txt ECHO adm is working! DEL C:\AVEVA\pdms11.6.SP1\pdmsuser\temp3.txt PING -n 1 -w 15000 1.1.1.1 > nul GOTO loop :yes ECHO. ECHO. ECHO adm is finished rename C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt KUPE-DICE-CHECK.txt MOVE C:\AVEVA\pdms11.6.SP1\pdmsuser\KUPE-DICE-CHECK.txt C:\PDMS\Results\Dice -- ------------------------------------------------------ It doesn't seem to completing the full code...it stops part way thgrough... Before I tell you the problem can I confirm that this symbol in the centre is the one on the backslash key on the keyboard...not sure of it's name:- exe" | find I created some dummy files and added delete code...to see how far the code got... The code made it to and past :- set errorlevel= It stopped at this line :- tasklist /fi "imagename eq adm.exe" | find /i "adm.exe"> NUL Have I made another typo ? Cheers Neil I got it working by modifying one line :- Old tasklist /fi "imagename eq adm.exe" l find /i "adm.exe"> NUL New tasklist /fi "imagename eq adm.exe" goto goto loop -- --------------------------- So it now looks like this :- @ECHO OFF :loop CLS ECHO adm is working! PING -n 1 -w 15000 1.1.1.1 > nul errorlevel= tasklist /fi "imagename eq adm.exe" goto goto loop if /i %errorlevel% GTR 0 goto yes :yes ECHO. ECHO. ECHO adm is finished FOR /F "TOKENS=1-4 DELIMS=/ " %%i in ('date /t') DO (SET DATE=%%i-%%j-%%k) rename C:\AVEVA\pdms11.6.SP1\pdmsuser\dice.txt KUPE-DICE-CHECK-%DATE%.txt MOVE C:\AVEVA\pdms11.6.SP1\pdmsuser\KUPE-DICE-CHECK-%DATE%.txt C:\PDMS\Results\Dice -- --------------------------- Thanks for the help... Neil |
|