Code: Alles auswählen
def start_stop():
befehl1 = ['ps', '-aux']
befehl2 = ['grep', 'ubung.py']
befehl3 = ['grep', '-v', 'grep']
subprocess.Popen(['/usr/bin/python3', '/home/matze/Schreibtisch/ubung.py'])
time.sleep(15)
command1 = subprocess.Popen(befehl1,stdout=subprocess.PIPE)
command2 = subprocess.Popen(befehl2, stdin=command1.stdout,stdout=subprocess.PIPE)
command3 = subprocess.Popen(befehl3, stdin=command2.stdout,stdout=subprocess.PIPE)
ergebnis = (command3.stdout.readline().decode("utf-8").split()[1])
beenden = ['kill', '-s', 'SIGINT',ergebnis]
subprocess.Popen(beenden)
Funktioniert tut es.
Es soll ein Python Script mit einer endlos Schleife und eingebauten 'try' beenden.
Heißt beim 'kill' wird 'except' ausgeführt und durch 'break' das ordentlich beendet.