0

Current I have this set of codes in a TEST.bat

@echo off
echo HELLO
pause

What I want to do is...

1) I play TEST.bat, it shows "HELLO" on a command prompt (Correct) 2) I play again, another windows pop up "HELLO" on a command prompt (correct behavior but.. )

Is it possible to do this

If(cmd.exe is running)
{
 close it
 play TEST.BAT
}
shin1234
  • 217
  • 1
  • 3
  • 12
  • 2
    Possible duplicate of [how to kill all batch files except the one currently running](http://stackoverflow.com/questions/12024149/how-to-kill-all-batch-files-except-the-one-currently-running) – JosefZ May 21 '16 at 07:56

1 Answers1

1

In theory you can just fire the taskkill command regardless if the task is running or not:

taskkill /f /im sometask.exe

If you really need to figure out if a task is running, you can do

tasklist | find "your task's name"

If afterwards %errorlevel% is 1, the task name was not found.

Florian Straub
  • 826
  • 9
  • 18