I'm trying to run small command-line code in java application to delete itself. So the command would keep running and keeps trying to delete the file, and once the application is closed it would be deleted.
I've tired passing the command into Runtime.getRuntime().exec but still unable to have it work.
eg:
SET file="program.jar"
goto :d
:r
timeout /t 1
:d
del %file%
if exist %file% goto :r
Tried doing this which obviously looks wrong. I've tired using ; instead of && but doesn't work either.
Runtime.getRuntime().exec("cmd /c \"SET file=\"program.jar\" && goto :d && :r && timeout /t 1 && :d && del %file% && if exist %file% goto :r\"");
Works perfectly well in a .bat file but how do i implement it into java .exec() method. I could just run the .bat file but I would want all the code be contained inside java.