In Python, you could programatically send a Ctrl+C
signal using os.kill. Problem is, you need the pid
of the process that'll receive the signal, and os.system
does not tell you anything about that. You should use subprocess
for that. I don't quite get what you said about not getting the output on the terminal.
Anyways, here's how you could do it:
import subprocess
import signal
import os
devnull = open('/dev/null', 'w')
p = subprocess.Popen(["./main"], stdout=devnull, shell=False)
# Get the process id
pid = p.pid
os.kill(pid, signal.SIGINT)
if not p.poll():
print "Process correctly halted"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…