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:
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?
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)
User contributions licensed under CC BY-SA 3.0