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.

For example: Given the following code snippet, the test to see if DEST.DOC exists must not run until after the COPY command has completed.

Code: [Select]COPY /Y SOURCE.DOC DEST.DOC
IF EXIST DEST.DOC (
ECHO DEST.DOC EXISTS
) ELSE (
ECHO DEST.DOC DOES NOT EXIST
How can I program the batch file commands to wait-until-complete?

Thanks

-Mikeyou could always just set up a test kinda of like what you have but if the file dose not exist then you can goto the top and wait for a few seconds then try again.

example:

Code: [Select]
COPY /Y SOURCE.DOC DEST.DOC

:loop

ping -n 1 -w 3000 1.1.1.1 > nul

IF EXIST DEST.DOC (
ECHO DEST.DOC EXISTS
) ELSE (
GOTO loop
)
Thanks wbrost,

Yes, I thought about doing something like what you suggest.

However, I've USED an option or something in the past WOULD instruct DOS not to proceed until the current command has completed.
I just can't remember what that option was.
It was something like placing a ; or something like this at the end of the command line.

Any one remember what this is?

Thanks

-MikeQuote from: Soniq2 on May 20, 2009, 01:06:48 PM

Thanks wbrost,

Yes, I thought about doing something like what you suggest.

However, I've used an option or something in the past would instruct DOS not to proceed until the current command has completed.
I just can't remember what that option was.
It was something like placing a ; or something like this at the end of the command line.

Any one remember what this is?

Thanks

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

tasklist /F1 "imaginename eq adm.exe"


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


Discussion

No Comment Found