简体   繁体   中英

How to send a stop command from python to terminal

Python sends:

os.system("sudo openvpn openvpn.ovpn")

to terminal

how do I tell terminal to listen to my next command I'm trying to send

sys.exit()

but it doesn't work

This program is coded with tkinter and there is a button to choose the vpn , but i want to make a stop button as well.

sys.exit will cause the current process exit. you can try POpen then use one one of

Popen.send_signal()
Popen.kill()
Popen.terminate()

to cause the subprocess quit. for example:

subp = subprocess.Popen("some command" )
subp.send_signal( 9 );
def clicked():
    process = subprocess.Popen(['sudo','openvpn','--config',var.get()])

def clicked2():
    process.kill()

process is in another defined function so I cannot recall it, anyway i can recall that in another function?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM