running adb with python: executing a program and ending it
<p>I am trying to perform adb interactions through python code.
I have an endless executable on the android device which i would like to start and after 10 seconds kill it.
right now, i can get the program to start but cannot kill it other the manually pressing ctrl+c.</p>

<pre><code>procID = subprocess.Popen(["adb", "shell"], stdin=subprocess.PIPE,)
procID.communicate('su\n endless_program data/test 5\n')
time.sleep(5)
os.kill(procID, signal.SIGINT)
procID.kill()
</code></pre>

<p>i tried killing it with os.kill or procID.kill but both don't seem to work.</p>

<p>I have also trying using pexpect, but for some reason i cant get it to run adb.</p>

<p>You are just killing the adb shell session, which won't kill the running application. If you would like to kill the running Android application, you have to stop the app over the adb shell. For details have a look at this <a href="https://stackoverflow.com/questions/17829606/android-adb-stop-application-command-like-force-stop-for-non-rooted-device#17829677">stackoverflow answer</a>.</p>

android python subprocess adb pexpect