0

I'm looking to write a python script that would allow me to start a jar file I have on my computer, wait 3 seconds and then kill it. Currently, I'm on step 2 and I can't find a way to kill my process. It's vital since if I forget to kill it, it's gonna occupy a port on my machine and I'm gonna have to manually find it and kill it by pid.

So, how do I do that ?

Thanks in advance, here's my small code:

from msilib.schema import Error
import psycopg2
import subprocess
import time

# Define the path where your jar is built
path = '...'
  
< some sql interactions >

conn.commit()
conn.close()

# Calling the java
subprocess.call(['java', '-jar', path])

time.sleep(3)

# kill the subprocess
Federico klez Culloca
  • 24,336
  • 15
  • 57
  • 93
Tom
  • 91
  • 9
  • Suggested post worked perfectly. `process = subprocess.Popen(['java', '-jar', path])` and then `process.terminate()`. Only problem is that I need to sleep the process long enough to wait for my java jar to do start (takes 7 to 9 seconds), and I don't know how to it in a clean way so I just `time.sleep(20)` – Tom Jun 02 '22 at 13:36

0 Answers0