0

I have a Python code, it opens Excel, but the Excel close command does not work!(python 3.9, windows 10).

code:

   def geeks():
      p = subprocess.Popen(r"test.xlsx", shell=True)

      while subprocess is not None:
          os.kill(p.pid, signal.SIGTERM)
          time.sleep(2)


 geeks()

error:

    os.kill(p.pid, signal.SIGTERM)
PermissionError: [WinError 5] Access is denied

I have been looking for the appropriate code for several days, but I can not find it.

What should I change in the code?

  • Does this answer your question? [How to cleanly kill subprocesses in python](https://stackoverflow.com/questions/41961430/how-to-cleanly-kill-subprocesses-in-python) – FlyingTeller Apr 11 '22 at 08:39
  • thanks, I have tried the examples given, but some are on Linux. I could not find a worker. – Tornike Kharitonishvili Apr 11 '22 at 08:57
  • It would improve your question if you included the variations that you have tried and stated what their behavior was. This way, you can make sure that there are no recommendations to try things you have already tried or attempts to close your question as a duplicate – FlyingTeller Apr 11 '22 at 09:13
  • I found a solution: subprocess.call(["taskkill", "/f", "/im", "EXCEL.EXE"]) – Tornike Kharitonishvili Apr 11 '22 at 09:22

1 Answers1

0

I found a solution:

while subprocess is not None:
 subprocess.call(["taskkill", "/f", "/im", "EXCEL.EXE"])
Troyer
  • 6,765
  • 3
  • 34
  • 62