I previously asked how to stop a program and was told/helped, however I neglected to mention the program was external. I wish to press a macro/key and have a external program run, and when pushed again it is stopped/halted all from this code. Eventually I hope to have many macro-keys toggling different programs on/start and off/stop.
I have searched and come up with a post from 2016 I think, I have adapted the code slightly, I have it working(starting) an external program but not stopping it. Code is run on Linux and written in python, it follows this, the EXTERNAL program is not killed or stopped.
What bug have I introduced, how to do it.
#!/usr/bin/env python
# Toggler for macro key -|- many keys = one toggler program
import os
import sys
import time
import subprocess
def startp(program):
return subprocess.Popen(program)
def exitp(p):
#os.close(program)#requires integer
p.terminate()
program = startp("firefox")
time.sleep(5)
# program = 'firefox'
exitp(program)
Perhaps someone can help find the bug in my program that I have adapted.
skeptic
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…