I need to call a DOS .exe file from Python and delete this .exe after the computation. I am able to call it using subprocess.Popen and os.system, however, I could not delete this .exe file if it is called by subprocess.Popen. The error is WindowsError: [Error 5] Access is denied. Can anyone let me know how to kill this process? Thanks!
subprocess approach (does not work):
a = subprocess.Popen("dos.exe", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) time.sleep(5) a.kill() os.remove("dos.exe") # gets error msg "WindowsError: [Error 5] Access is denied" os.system approach (works):
a=os.system("dos.exe") os.remove("dos.exe")