I need to run a command adb get-state from my python library.
I used
subprocess.popen
to execute the command and killed the process using pid.
If the adb daemon is not in running state, adb process will create an extra adb process and terminate the first process created after starting the daemon (even manually its the same).
Hence I am not able to kill the adb process opened by subprocess open since it has the pid of the first adb process (which has already terminated)
Is there any way I can kill the real adb process which executes the command from python.
I will suggest you yo kill all the running processes of adb before starting a new one . Here is some sample code that can kill already running process under windows environment.
This code Kills any adb process that is already running and then opens a new process daemon for adb
Sample Code :
import subprocess
import os
p = subprocess.Popen("tasklist", stdout=subprocess.PIPE)
RunningProcessLIst = p.stdout.readlines()
print("Kill all running instances of adb.exe")
for runningPro in RunningProcessLIst :
if "adb.exe" in str(runningPro) :
os.system("taskkill /F /IM adb.exe")
process =subprocess.Popen("I:\\adb\\Win32\\adb.exe adb get-state") # you subprocesses call will be here
Hope this helps
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.