简体   繁体   English

如何从python向终端发送停止命令

[英]How to send a stop command from python to terminal

Python sends: Python发送:

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. 这个程序是用tkinter编码的,有一个按钮可以选择vpn ,但是我也想做一个停止按钮。

sys.exit will cause the current process exit. sys.exit将导致当前进程退出。 you can try POpen then use one one of 您可以尝试POpen,然后使用以下一项

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? 进程在另一个定义的函数中,因此我无法调用它,无论如何我可以在另一个函数中调用它?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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