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,blah
timeout>nul 2 /nobreak
set /p input=
if /i "%input%"=="hi there" (
goto infinite_loop
) ELSE (
goto the_other_infinite_loop
):infinite_loop
echo hi
pause
goto infinite_loop:the_other_infinite_loop
echo this is the other loop!
pause
goto the_other_infinite_loopApologies for the lack of info...
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".
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?
Save the text file as a .bat and use call from within the first batch. As in
Call c:\mybatchname.bat
:: mike
do i have to change the text file to a batch file?
Not nessicarily however it might be easier :: mike
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 off
for /f "tokens=*" %%x in (%cd%\test.txt) do (
call %%x
)and this is the text file:
echo hi
set /p input=
if /i "%cmd%"=="hi" (
goto hi
) ELSE (
goto bye
):hi
echo hi
exit
:bye
echo bye
exitany idea's on whats going wrong?
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
You could cheat and use a temporary file if you wanted to. type test.txt > tmp.bat
then call the tmp.bat
and then delete the tmp.bat
this would leave the text file intact, and if you are using multiple text files it would work for any of them.
:: mike
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |