finshore Posted September 17, 2009 Share Posted September 17, 2009 (edited) This batch runs good until i stress test it by running it a lot. The copy command that is supposed to change dn.ini does not seem to execute when it fails.SET DIR=%~dp0taskkill /FI "status eq running" /IM dn.exexcopy "%DIR%script\dn" "%DIR%dn\dn.ini" /ystart script\dn.vbsstart dn\dn.exepauseLet me explain exactly what im trying to do in case im doing it wrong:first sets current directory to %dir% so i can place it anywherethen it closes dn.exethen copys over dn.ini which is used by dn.exethen runs a .vbs script which just simulates a keypressthen it starts dn.exe againI am not a programmer so I don't know if there is a real simple fix. But I was wondering if i could move my copy command and create a call to it to ensure that it executes. Would that work and how would i do it? Edited September 17, 2009 by finshore Link to comment Share on other sites More sharing options...
Yzöwl Posted September 18, 2009 Share Posted September 18, 2009 It's not clear to me exactly what you are trying to do, so I'm going to ask!Currently, if dn.exe isn't running you are still xcopying then running the vbs, is this your intention or do you want to run it only if you've had to terminate the executable.Currently you appear to be copying, a directory to a filename. If script\dn is a extensionless filename then ignore this remark)Currently you are starting the dn.exe executable at the end of your script. Is this your intention or are you wanting to start it only if you've had to terminate it earlier in the script? Link to comment Share on other sites More sharing options...
finshore Posted September 18, 2009 Author Share Posted September 18, 2009 Ok, sorry, I wasn't sure what was causing the fail before, but it seems that it cannot xcopy to dn.ini because dn.exe is trying to utilize it when it starts up.So i just need to make sure xcopy completes before dn.exe starts again, but I am able to xcopy before killing dn.exe.and yes dn is just a text file with no extension. Link to comment Share on other sites More sharing options...
finshore Posted September 18, 2009 Author Share Posted September 18, 2009 To clarify, I do need to stop dn.exe and start it again with the new dn.ini settings registered. Link to comment Share on other sites More sharing options...
finshore Posted September 18, 2009 Author Share Posted September 18, 2009 Think i found a solution. Enclosed the file copy in a loop that tested the file for change.SET DIR=%~dp0taskkill /FI "status eq running" /IM dn.exe:TESTxcopy "%DIR%script\dn" "%DIR%dn\dn.ini" /yfind /c "%6419%" "%DIR%dn\dn.ini" REM 6419 being a new block of text that was changed by xcopyIF %ERRORLEVEL% == 1 goto TESTstart script\dn.vbsstart dn\dn.exepause Link to comment Share on other sites More sharing options...
Yzöwl Posted September 18, 2009 Share Posted September 18, 2009 Although you say you've solved it, I think that the loop your using is unnecessary.Here is an educational method which is a little long-winded but hopefully explains the thought process a little better.@ECHO OFF & SETLOCAL ENABLEEXTENSIONSREM CHECKS TO SEE IF DN IS RUNNINGTASKLIST /FI "IMAGENAME EQ DN.EXE" /FO CSV /NH >NUL && (SET _= /WAIT )REM IF DN PROCESS WAS RUNNING THEN TERMINATE ITREM SINCE PROCESSES MAY TAKE A WHILE TO TERMINATE USES A WAIT PROCEDUREIF DEFINED _ START /WAIT /B TASKKILL /IM DN.EXE /F >NULREM MAKE SURE THAT YOUR CURRENT DIRECTORY IS THAT OF THE RUNNING SCRIPTPUSHD %~dp0REM COPY YOUR EXTENSIONLESS INI FILE TO DESTINATIONCOPY SCRIPT\DN DN\dn.ini >NULREM IF YOUR INI COPY IS THE BOTTLENECK YOU COULD USE THIS INSTEADREM START /WAIT /B COPY SCRIPT\DN DN\dn.ini >NULREM RUN YOUR VBSCRIPTREM IF DN WAS TERMINATED AND IS TO BE RERUN USE WAIT PROCEDURE ON EXTERNAL SCRIPT PROCESSINGREM SINCE ITS POSSIBLE THAT THIS PROCESS MAY NOT BE IMMEDIATESTART%_%/B SCRIPT\DN.VBSREM IF DN WAS RUNNING THEN RESTART ITIF DEFINED _ START DN\DN.EXEI hope it helps somewhat. Link to comment Share on other sites More sharing options...
finshore Posted September 19, 2009 Author Share Posted September 19, 2009 Thanks, it works real good. I like the "start /wait" and "&&", didnt know about them before.Only altered a couple things. I put % around the variable before taskkill, and removed the condition for starting dn.exe at the bottom, because i want that to start no matter what. Link to comment Share on other sites More sharing options...
Yzöwl Posted September 19, 2009 Share Posted September 19, 2009 I'm glad to have helped you to further your knowledge. Link to comment Share on other sites More sharing options...
finshore Posted September 19, 2009 Author Share Posted September 19, 2009 I was able to take the loop out of the first script and use "start /wait" instead, works really nice, no errors.@echo offstart /b /wait taskkill /FI "status eq running" /IM dn.exestart /b /wait xcopy "%~dp0script\dn" "%~dp0dn\dn.ini" /ystart %~dp0script\dn.vbsstart %~dp0dn\dn.exe Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now