How to launch a process from Python without locking execution folder?

0

Before open this question, I was looking at similar question, but its answer does not work in this case. After I start the process, I want to delete script folder, but I cannot. My code:

from subprocess import Popen

DETACHED_PROCESS = 0x00000008
CREATE_NEW_PROCESS_GROUP = 0x00000200

app = r"C:\Windows\notepad.exe"

Popen(app, creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, close_fds=True)

After running the script, I want to delete script folder, and I get:

enter image description here

I can delete the folder only if I close the process. Do you have any suggestion about how can I start the process without locking script folder?

python
asked on Stack Overflow May 22, 2020 by A. Ilie

1 Answer

0

Do you mean you want to delete the folder containing the python script itself? That sounds a bit sketchy.

me = os.path.abspath(sys.argv[0])
where = os.path.dirname(me)
args = ['cmd.exe', '/C', 'rd', '/S', '/Q', where]
Popen(args, creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, close_fds=True)
answered on Stack Overflow May 22, 2020 by Justin Ezequiel

User contributions licensed under CC BY-SA 3.0