mte01
asked on
Batch File to wait & close running programs
Hey experts,
I have the following commands at the beginning of a batch file:
cd C:\Documents and Settings\Mohamad\My Documents\PTT Pro\ThinClientB\build\clas ses
start java PTT_ClientB.ClientBTester a101 a101
start java PTT_ClientB.ClientBTester a102 a102
start java PTT_ClientB.ClientBTester a103 a103
start java PTT_ClientB.ClientBTester a104 a104
start java PTT_ClientB.ClientBTester a105 a105
cd C:\Documents and Settings\Mohamad\My Documents\PTT Pro\ThinClientA\build\clas ses
start java PTT_ClientA.ClientATester a1 a1 03100101
start java PTT_ClientA.ClientATester a2 a2 03100102
start java PTT_ClientA.ClientATester a3 a3 03100103
start java PTT_ClientA.ClientATester a4 a4 03100104
start java PTT_ClientA.ClientATester a5 a5 03100105
After the following, I want to wait for a certain amount of time (let's say 20 seconds), and then I want to close the above running programs (if they are still running)...any help on that??
I have the following commands at the beginning of a batch file:
cd C:\Documents and Settings\Mohamad\My Documents\PTT Pro\ThinClientB\build\clas
start java PTT_ClientB.ClientBTester a101 a101
start java PTT_ClientB.ClientBTester a102 a102
start java PTT_ClientB.ClientBTester a103 a103
start java PTT_ClientB.ClientBTester a104 a104
start java PTT_ClientB.ClientBTester a105 a105
cd C:\Documents and Settings\Mohamad\My Documents\PTT Pro\ThinClientA\build\clas
start java PTT_ClientA.ClientATester a1 a1 03100101
start java PTT_ClientA.ClientATester a2 a2 03100102
start java PTT_ClientA.ClientATester a3 a3 03100103
start java PTT_ClientA.ClientATester a4 a4 03100104
start java PTT_ClientA.ClientATester a5 a5 03100105
After the following, I want to wait for a certain amount of time (let's say 20 seconds), and then I want to close the above running programs (if they are still running)...any help on that??
Use a sleep command to sleep the desired amount of time, then use a for command and tasklist to cycle through the process list and close any open Java processes.
ASKER
>>Use a sleep command
for example:
sleep 20
??
>>then use a for command and tasklist to cycle through the process list and close any open Java processes
how do I do that??
for example:
sleep 20
??
>>then use a for command and tasklist to cycle through the process list and close any open Java processes
how do I do that??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great...but I am still a beginner in batch file programming...can you please explain the line of code that you just wrote above...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ahaa I see...I'll be trying it....but also please explain the line of code of the for loop...
You can use taskkill to kill by name as well... I just prefer using Process IDs.
tokens refers to the column(s) to use as the variables(s), starting with, in my example, %a.
If you type tasklist at a command prompt, there are several columns, the second is the process ID. So that gets assigned to %a each time through the loop. (default delimiters are space and tab, others can be specified). the in () part is referring to what contains the information to cycle through. In this case, it's the command 'tasklist | find /i "java"' which itself is a combination of two commands, one listing the processes, the other searching through that list for "java", ignoring the case (Java vs. JAVA, vs java, etc). Then DO the following command which is to kill the process in question.
tokens refers to the column(s) to use as the variables(s), starting with, in my example, %a.
If you type tasklist at a command prompt, there are several columns, the second is the process ID. So that gets assigned to %a each time through the loop. (default delimiters are space and tab, others can be specified). the in () part is referring to what contains the information to cycle through. In this case, it's the command 'tasklist | find /i "java"' which itself is a combination of two commands, one listing the processes, the other searching through that list for "java", ignoring the case (Java vs. JAVA, vs java, etc). Then DO the following command which is to kill the process in question.
ASKER
>>leew
Ok..thanks for your help!!
>>leew,jkr
I can't find a proper sleep.exe file on the internet...any help??
Ok..thanks for your help!!
>>leew,jkr
I can't find a proper sleep.exe file on the internet...any help??
Try downloading the Resource Kit Tools for 2003 Server - they should work on XP:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
ASKER
>>leew
I hope it works...I'll be trying it shortly, and I'll inform you of the results......
I hope it works...I'll be trying it shortly, and I'll inform you of the results......