How do I terminate a shell program through python
Clash Royale CLAN TAG#URR8PPP
How do I terminate a shell program through python
Let's say I do somthing like this:
import os
os.system('java some_program.jar')
Is there a way to stop the execution of that program through python?
My situation:
I have a program in java that does some stuff and inserts data into a .csv file and I need to run it through python (because I'm using python for handeling the data in the .csv file) but the program itself doesn't stop by itself so i need a way to stop it manually once it inserts the data into the .csv file
2 Answers
2
Don't use os.system
.
os.system
Instead, use p = subprocess.Popen(...)
. Then simply call p.kill()
.
p = subprocess.Popen(...)
p.kill()
Also, your Java program should be updated to exit when it sees EOF on stdin.
You could try having the java program echo to console or something that it is finished writing to the CSV file using the subprocesses library and it's check_output function. And when that is done, use something like this: os.system("taskkill /im some_program.jar")
to kill off the program.
os.system("taskkill /im some_program.jar")
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.