1def check_process():
2 import subprocess
3 script_name = "test.py"
4 cmd='pgrep -f .*python.*{}'.format(script_name)
5 process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
6 my_pid, err = process.communicate()
7 if len(my_pid.splitlines()) >0:
8 print("Script Running in background")
9 sys.exit(0);
10check_process()
1#Cmd
2C:\..\>cd DIRECTORY
3C:\..\DIRECTORY>pythonw python.py
4#Close in Task Manager