I have a .bat
script launching a java
program.
The java
program deletes the folder where the .bat
sits.
I have no way to touch the java
program. I only can modify the .bat
file.
The problem is that the .bat
file, once deleted, stops its execution right away without finishing.
But there are some cleanup tasks to be done after the java
program exits.
I tried to copy the .bat
file somewhere else and launch it in a location where it would not be deleted. Alas, once the original .bat
is deleted, because it is still in execution, the same crash happens and it does not finish.
Here are two sample files (for the purpose of the example, let's pretend they are located in D:\tmp
) :
delete.bat
echo "delete start"
pause
del launch.bat
pause
echo "delete end"
launch.bat
echo "launch start"
setlocal enabledelayedexpansion enableextensions
if "%CD%"=="C:\tmp" (
echo "in temp"
d:
cd \tmp
delete.bat
)
if "%CD%" NEQ "C:\tmp" (
echo "not in temp"
mkdir C:\tmp
copy launch.bat C:\tmp\launch.bat
echo "launch copied"
C:
cd \tmp
cmd /c launch.bat
)
echo "launch end"
Launching launch.bat
would work if the execution of the copied launch.bat
were separated from the initial one.
Does anyone know a way to make a .bat
end up its execution even if it is deleted while it executes ?