Link to home
Start Free TrialLog in
Avatar of CPUAffinity
CPUAffinityFlag for United States of America

asked on

Need Batch File to Exit After Running

I need a batch file to close after running.  Every time I've found a way to get the file to close after doing its job, it fails to launch the program specified.  If I get the file to launch the program specified, it will not close.  As listed below, the file will launch the program, but will not close the batch window.  If i remove the live launching HTTPSyncStat, the window will exit just fine.  I have not played with batch files in quite some time.  Help!



tskill httpsyncstat /A
tskill httpxpt /A
tskill msync /A

@echo off
   echo Pausing for 5 seconds...
   call :pause 5
   "c:\Program Files\CDC Software\Pivotal CRM\SyncStream\httpsyncstat.exe"
   exit /b

:pause
setlocal
set t1=%time%
set t1=%t1::=%
set t1=%t1:~0,6%
set t1=0%t1: =%
set t1=%t1:~-6%
set /a t1=%t1%+%1

:loop
   set t2=%time%
   set t2=%t2::=%
   set t2=%t2:~0,6%
   set t2=0%t2: =%
   set t2=%t2:~-6%
if %t2% LSS %t1% goto :loop

endlocal
exit /b

Open in new window

Avatar of giltjr
giltjr
Flag of United States of America image

Try changing":

   "c:\Program Files\CDC Software\Pivotal CRM\SyncStream\httpsyncstat.exe"


to

     start    "c:\Program Files\CDC Software\Pivotal CRM\SyncStream\httpsyncstat.exe"
Avatar of Bill Prew
Bill Prew

In the main routine, just before the exit /b, why not add a pause to give the EXE a chance to launch, maybe another 5 seconds.  Then change the exit /b to just an exit.

~bp
Ah yes, START will be needed, doh.  

Without the START the batch file will wait for the EXE to finish before it continues.  With the START it will launch the EXE, and then continue running.  At that point the exit /b should close it out just fine.

~bp
If you use the "start" command to launch the program on line 8, it will launch that program in a separate window.  If you wish to run that program in the same window as the original batch program, use "start /B".
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As the first parameter in quotes is seen as the window title... nice gotcha with START!
Avatar of CPUAffinity

ASKER

With START added, the window does close, but just before it closes it launches another CMD window with the program path in the title bar, but the program does not launch & this window remains open at the C:\Documents and Settings\profile_name_here\Desktop>

Adding the additional pause yields the initial result.
Another good point on the START quirky syntax, I remember getting bit by that and not believing it at the time.

FWIW, a simpler way to delay fo 5 seconds would be:

PING -n 1 -w 5000 1.1.1.1>NUL

This uses the PING command to attempt to ping a nonexistant IP, and waits for 5 seconds to timeout.

~bp
dragon-it.  thanks for catching that.  I forgot about the title part.
CPUAffinity: that is the extra issue I suggested then.  Please try what I posted above and should be good to go hopefully.

Steve
That did the trick, Thanks!
No problem, sorry for jumping in there everyone ;-)
Actually there is a sleep command that MS provides in their server tool kits:

     http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

It is a little better than the ping trick, but if you don't want to get sleep then the ping trick is the way to go.