0

I have my main batch file with all of the coding in it. I want to keep my coding nicely organised so what I want to do is to make my main batch file read code off multiple .txt files and display the code on its window.

Lets say I do something like this:

if %TEST%==1 for /f "Delims=" %%a in (test.txt) do (set TEXT=%%a) echo %TEXT%

This echos the whole text that is inside the .txt but how do I make it run the code? Also how do I make my main batch file echo specific lines of the .txt file?

  • What do you mean by `make it run the code`? – Bali C Apr 06 '17 at 14:34
  • 2
    Just remove the `echo` – SomethingDark Apr 06 '17 at 14:48
  • I agree with @SomethingDark but more complex code with labels/gotos/calls or delayed expansion won't work that easily. Otherwise to execute code in other batch files simply [call](http://ss64.com/nt/call.htm) them after renaming with bat/cmd extension. –  Apr 06 '17 at 15:15
  • How do I now make the command read specific lines of the code? Could you also tell me some other syntaxes that change the way that the batch file reads the .txt? For example how to make it read everything and not just the last line..? – Boomerang Apr 06 '17 at 18:38
  • If you want to read _commands_ from the .txt file and execute they, then this only works with simple commands, that is, this _not_ works with `if` and `for` _compound_ commands (unless _complete commands_ are read and executed). You may read several lines from the .txt file and store they in an _array_, so you may show/execute specific lines; see [this answer](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) for further details... – Aacini Apr 06 '17 at 22:40

1 Answers1

0

Why dont you save the other scripts a .bat and call them with start script.bat. I dont think there is a way you could read from a text file and execute the writen text as script. Or you try setting something up lile `set command = your string here

call %%command%%`

CipherWise
  • 24
  • 3