# Batch commands from text file

March 5, 2013 at 20:55:27
 hey guys, i've been playing around with batch files and i want to know if it's possible to load commands out of text files, for example:text file:echo blah,blah,blahtimeout>nul 2 /nobreakset /p input=if /i "%input%"=="hi there" (goto infinite_loop) ELSE (goto the_other_infinite_loop):infinite_loopecho hipausegoto infinite_loop:the_other_infinite_loopecho this is the other loop!pausegoto the_other_infinite_loopApologies for the lack of info...

See More: Batch commands from text file

#1
March 5, 2013 at 21:23:15
 I think you've answered your own question."load commands out of text files"is pretty much the definintion of a script, except substitute "run" for "load".

Report •

#2
March 5, 2013 at 21:43:25
 sorry, i didnt explain properly,what i meant was, i have a batch file with a few commands already in it, but i also have a few other text files with other commands.is there a way for the user to select a text file and whatever code is in that text file will be run?

Report •

#3
March 5, 2013 at 21:59:57
 Save the text file as a .bat and use call from within the first batch.As inCall c:\mybatchname.bat:: mike

Report •

Related Solutions

#4
March 5, 2013 at 22:07:43
 do i have to change the text file to a batch file?

Report •

#5
March 6, 2013 at 01:48:38
 Not nessicarily however it might be easier:: mike

Report •

#6
March 6, 2013 at 21:32:42
 I've managed to find some script that allows me to make the batch file execute the text in the .txt file, but for some reason as soon as it reaches a "goto" command the batch file says:"the system cannot find the batch label specified - main""invalid attempt to call batch label outside of batch script"this is the batch file:@echo offfor /f "tokens=*" %%x in (%cd%\test.txt) do ( call %%x)and this is the text file:echo hiset /p input=if /i "%cmd%"=="hi" (goto hi) ELSE (goto bye):hiecho hiexit:byeecho byeexitany idea's on whats going wrong?

Report •

#7
March 7, 2013 at 06:51:01
 The label bye and label hi are not in the batch that you initialized. it is reading line by line the text file and the command to goto effects the original batch, not the text file.:: mike

Report •

#8
March 8, 2013 at 06:44:22
 You could cheat and use a temporary file if you wanted to.type test.txt > tmp.batthen call the tmp.batand then delete the tmp.batthis would leave the text file intact, and if you are using multiple text files it would work for any of them.:: mike

Report •

#9
March 13, 2013 at 22:04:31
 Cool, thanks for all the help guys, it really helped!

Report •