MSFN Forum: simple batch - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

simple batch close program, edit ini, start program Rate Topic: -----

#1 User is offline   finshore 

  • Group: Members
  • Posts: 6
  • Joined: 17-September 09

Posted 17 September 2009 - 09:38 AM

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?

This post has been edited by finshore: 17 September 2009 - 04:25 PM



#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 18 September 2009 - 02:01 AM

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?

#3 User is offline   finshore 

  • Group: Members
  • Posts: 6
  • Joined: 17-September 09

Posted 18 September 2009 - 03:23 AM

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.

#4 User is offline   finshore 

  • Group: Members
  • Posts: 6
  • Joined: 17-September 09

Posted 18 September 2009 - 04:51 AM

To clarify, I do need to stop dn.exe and start it again with the new dn.ini settings registered.

#5 User is offline   finshore 

  • Group: Members
  • Posts: 6
  • Joined: 17-September 09

Posted 18 September 2009 - 05:50 AM

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


#6 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 18 September 2009 - 02:25 PM

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.

Quote

@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.

#7 User is offline   finshore 

  • Group: Members
  • Posts: 6
  • Joined: 17-September 09

Posted 19 September 2009 - 01:46 PM

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.

#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 19 September 2009 - 02:36 PM

I'm glad to have helped you to further your knowledge.

#9 User is offline   finshore 

  • Group: Members
  • Posts: 6
  • Joined: 17-September 09

Posted 19 September 2009 - 03:34 PM

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


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy