How can i run a command on the command prompt with a batch file and keep running it for 'n' seconds?
<p>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)</p>

<p>Use the <code>subprocess</code> module. You may be interested in <code>subprocess.run</code> and its <code>timeout</code> argument if you are using a newer version of Python (i.e. 3.5.x). If not, take a look at <code>subprocess.Popen</code>.</p>

<blockquote>
  <p>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.</p>
</blockquote>

<hr>

<p>Reference: <a href="https://docs.python.org/3/library/subprocess.html#subprocess.run" rel="nofollow">https://docs.python.org/3/library/subprocess.html#subprocess.run</a></p>

python python-2.7 python-3.x command-line subprocess