Question: How can i run a command on the command prompt with a batch file and keep running it for 'n' seconds ? and then close it automatically ? (All in Background i.e without opening the console)

Answer: 
Create any python(.py) file and run it like

`c:\python27\python.exe <path_of_the_file>/filename.py`

To keep running it over say, 1000 times:

`for /l %x in (1, 1, 1000) do c:\python27\python.exe <path_of_the_file>/filename.py`

Note: Assuming your python is installed at c:\python27\
Use the `subprocess` module. You may be interested in `subprocess.run` and its `timeout` argument if you are using a newer version of Python (i.e. 3.5.x). If not, take a look at `subprocess.Popen`.

> 
> The timeout argument is passed to Popen.communicate(). If the timeout expires, the child process will be killed and waited for. The TimeoutExpired exception will be re-raised after the child process has terminated.
> 
> 
> 

---

Reference: <https://docs.python.org/3/library/subprocess.html#subprocess.run>