Jump to content

simple batch


Recommended Posts

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=%~dp0
taskkill /FI "status eq running" /IM dn.exe
xcopy "%DIR%script\dn" "%DIR%dn\dn.ini" /y
start script\dn.vbs
start dn\dn.exe
pause

Let 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 anywhere

then it closes dn.exe

then copys over dn.ini which is used by dn.exe

then runs a .vbs script which just simulates a keypress

then it starts dn.exe again

I 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 by finshore
Link to comment
Share on other sites


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

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

Think i found a solution. Enclosed the file copy in a loop that tested the file for change.

SET DIR=%~dp0

taskkill /FI "status eq running" /IM dn.exe

:TEST
xcopy "%DIR%script\dn" "%DIR%dn\dn.ini" /y
find /c "%6419%" "%DIR%dn\dn.ini" REM 6419 being a new block of text that was changed by xcopy
IF %ERRORLEVEL% == 1 goto TEST

start script\dn.vbs
start dn\dn.exe
pause

Link to comment
Share on other sites

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 ENABLEEXTENSIONS

REM CHECKS TO SEE IF DN IS RUNNING

TASKLIST /FI "IMAGENAME EQ DN.EXE" /FO CSV /NH >NUL && (SET _= /WAIT )

REM IF DN PROCESS WAS RUNNING THEN TERMINATE IT

REM SINCE PROCESSES MAY TAKE A WHILE TO TERMINATE USES A WAIT PROCEDURE

IF DEFINED _ START /WAIT /B TASKKILL /IM DN.EXE /F >NUL

REM MAKE SURE THAT YOUR CURRENT DIRECTORY IS THAT OF THE RUNNING SCRIPT

PUSHD %~dp0

REM COPY YOUR EXTENSIONLESS INI FILE TO DESTINATION

COPY SCRIPT\DN DN\dn.ini >NUL

REM IF YOUR INI COPY IS THE BOTTLENECK YOU COULD USE THIS INSTEAD

REM START /WAIT /B COPY SCRIPT\DN DN\dn.ini >NUL

REM RUN YOUR VBSCRIPT

REM IF DN WAS TERMINATED AND IS TO BE RERUN USE WAIT PROCEDURE ON EXTERNAL SCRIPT PROCESSING

REM SINCE ITS POSSIBLE THAT THIS PROCESS MAY NOT BE IMMEDIATE

START%_%/B SCRIPT\DN.VBS

REM IF DN WAS RUNNING THEN RESTART IT

IF DEFINED _ START DN\DN.EXE

I hope it helps somewhat.

Link to comment
Share on other sites

Thanks, it works real good. :thumbup

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

I was able to take the loop out of the first script and use "start /wait" instead, works really nice, no errors.

@echo off

start /b /wait taskkill /FI "status eq running" /IM dn.exe

start /b /wait xcopy "%~dp0script\dn" "%~dp0dn\dn.ini" /y

start %~dp0script\dn.vbs

start %~dp0dn\dn.exe

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...