1.

Solve : Can batch files edit themselves??

Answer» <html><body><p>I was wondering if it is possible to use a batch file to edit part of another batch file (or itself)<br/><br/>ie:<br/>batch1<br/>:Label1<br/>set name=Fuzzy<br/><br/>:Label2<br/>set name=<a href="https://interviewquestions.tuteehub.com/tag/fluffy-7385704" style="font-weight:bold;" target="_blank" title="Click to know more about FLUFFY">FLUFFY</a><br/>-----------------------<br/>batch2<br/>findstr "Fluffy" batch1 ...(<a href="https://interviewquestions.tuteehub.com/tag/change-238106" style="font-weight:bold;" target="_blank" title="Click to know more about CHANGE">CHANGE</a> Fluffy to Furry)<br/>------------------------------------------------------------<br/>after running batch2, batch1 would read:<br/><br/>:Label1<br/>set name=Fuzzy<br/><br/>:Label2<br/>set name=Furry<br/>---------------------<br/>is that possible? (hopefully it's at least an understandable question)Yes, it is possible -- you might have to call a helper batch to make the edit then re-invoke it, I cannot remember if a batch is locked while running - it <a href="https://interviewquestions.tuteehub.com/tag/may-557248" style="font-weight:bold;" target="_blank" title="Click to know more about MAY">MAY</a> even be cached too.<br/><br/>However, it might be a tidier approach to store these values in a file and test against that - there would be no difficulty editing a separate text file. Also, no system manager wants to have a self-modyfing program on the system, this opens up all sorts of security issues.Depending on what code is being run, the batch file can continue without <a href="https://interviewquestions.tuteehub.com/tag/error-25548" style="font-weight:bold;" target="_blank" title="Click to know more about ERROR">ERROR</a>, but most often you will get some obscure error involving an unknown command (even though there isn't). Quote from: Helpmeh on November 04, 2010, 07:46:32 PM</p><blockquote>Depending on what code is being run, the batch file can continue without error, but most often you will get some obscure error involving an unknown command (even though there isn't).<br/></blockquote> <br/>Yes, because when the command interpreter executes a command or program, it stores its position in the script, and if you alter the code size prior to that, when cmd.exe returns, it still returns to that byte position. If it now lands in the middle of a word or command, it may have <a href="https://interviewquestions.tuteehub.com/tag/nonsense-580746" style="font-weight:bold;" target="_blank" title="Click to know more about NONSENSE">NONSENSE</a> to interpret.<br/>That would explain it! Thanks Salmon!</body></html>


Discussion

No Comment Found