python - Terminate a gnome-terminal opened with subprocess -
using subprocess , command 'gnome-terminal -e bash' can open gnome-terminal desired (and have stick around). done either
p=subprocess.popen(['gnome-terminal', '-e', 'bash']) or
p=subprocess.popen(['gnome-terminal -e bash'], shell=true) but cannot close terminal using p.terminate() or p.kill(). understand, little trickier when using shell=true did not expect run problems otherwise.
to terminate terminal , children (in same process group):
#!/usr/bin/env python import os import signal import subprocess p = subprocess.popen(['gnome-terminal', '--disable-factory', '-e', 'bash'], preexec_fn=os.setpgrp) # here... os.killpg(p.pid, signal.sigint) --disable-factoryused avoid re-using active terminal can kill newly created terminal viasubprocesshandleos.setpgrpputsgnome-terminalin own process groupos.killpg()used send signal group
Comments
Post a Comment