Agree it looks bad in principle, but it was a solution to a problem and it worked. I forget the total logic (despite being so pleased when I got it working) but it was along the lines of reading an input file, spawning a new batch file from the variables input, making sure only x batch files were running concurrently, code in batch files self healing if certain conditions were met, then on completion a self destruction to delete the batch file that was running before closing down and thus freeing up a new session that the master batch file would see and so spawn a new one.
A very dirty way to get through a source file, in multiple windows, where each window was running through a number of logical fixes to x remote computers based on the status it was reading and the results of what it was finding. Big_Boss wanted me to fix lots of machines before the user had a bigger problem and called the helldesk, but the computer next to me was doing it for me. All I needed to do was to look at any window that hadn't closed, remote on and diagnose the fault, and see if I could improve the source batch that was writing the other code so that a new fix went in; whether that was in the source or the crazy self changing code that the source had produced and was re-writing itself in the temporary code that was only existent for the time it had been created and before it deleted itself.
Biggest problems were keeping $Input_file current (ruddy machines kept breaking, users went offline), or turning up at the office to find a hotdesking colleague had stolen borrowed the network cable and not plugged it back in.
Luckily this was over a decade ago and long since not in use.