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

CPUAffinityAsked:
Who is Participating?
 
Steve KnightIT ConsultancyCommented:
Comment #1 is nearly right.  You will need to use an extra parameter as there are quotes around the filename:
START "Window title" "c:\Program Files\CDC Software\Pivotal CRM\SyncStream\httpsyncstat.exe"

or just

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

Steve
0
 
giltjrCommented:
Try changing":

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


to

     start    "c:\Program Files\CDC Software\Pivotal CRM\SyncStream\httpsyncstat.exe"
0
 
Bill PrewCommented:
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
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Bill PrewCommented:
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
0
 
GPruettCommented:
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".
0
 
Steve KnightIT ConsultancyCommented:
As the first parameter in quotes is seen as the window title... nice gotcha with START!
0
 
CPUAffinityAuthor Commented:
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.
0
 
Bill PrewCommented:
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
0
 
giltjrCommented:
dragon-it.  thanks for catching that.  I forgot about the title part.
0
 
Steve KnightIT ConsultancyCommented:
CPUAffinity: that is the extra issue I suggested then.  Please try what I posted above and should be good to go hopefully.

Steve
0
 
CPUAffinityAuthor Commented:
That did the trick, Thanks!
0
 
Steve KnightIT ConsultancyCommented:
No problem, sorry for jumping in there everyone ;-)
0
 
giltjrCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.