[英]Shell script kill command
I am trying to run and kill my shell script through a Python script.我正在尝试通过 Python 脚本运行并杀死我的 shell 脚本。 The purpose is so that I can simply press "Run" in my py script, instead of having to go through the terminal every time.目的是让我可以在我的 py 脚本中简单地按“运行”,而不必每次都通过终端 go。 Here is my shell script (T.sh):这是我的 shell 脚本(T.sh):
#!/bin/bash
#Track command
cd /home/pi/rpi-deep-pantilt
. . /rpi-deep-pantilt-env/bin/activate
rpi-deep-pantilt track Raspi --edge-tpu
Here is my Py script:这是我的 Py 脚本:
import os
os.system('bash /home/pi/T.sh')
When I issue the command rpi-deep-pantilt track Raspi --edge-tpu
in my terminal and press CTRL + C it kills the script, but it doesn't work when I use this Python script, and neither does pkill.当我在终端中发出命令rpi-deep-pantilt track Raspi --edge-tpu
并按CTRL + C时,它会杀死脚本,但是当我使用此 Python 脚本时它不起作用,pkill 也不起作用。 The Python script stops, but the camera stays on and the tracking functionality is still operating. Python 脚本停止,但摄像头保持开启,跟踪功能仍在运行。 Is there any way I can incorporate some kill command that I can issue with a key interruption?有什么方法可以合并一些可以通过按键中断发出的 kill 命令?
If there is a better way to go about this let me know.如果有关于 go 的更好方法,请告诉我。 I'm very new to this as you can probably tell.正如您可能知道的那样,我对此很陌生。
Python may create a new process for T.sh, so within your python code, try: Python 可能会为 T.sh 创建一个新进程,因此在您的 python 代码中,尝试:
os.system("pkill T.sh")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.