I'm not really used to making batch files, so I'm probably doing something wrong, but I'm really having trouble with echo off/on. (That said, if you see any other error that I missed, feel free to point it out)
Here's a simplified version of my code:
@echo off
setlocal
set args=
set dir="."
:getargs
IF "%2"=="" (
set dir="%1"
goto callbatch
)
set args=%args% %1
shift
goto getargs
:callbatch
for %%f in (%dir%\*.txt) do (
echo processing %%f
"%BATCHHOME%\batch.bat %args% %%f
echo
)
So basically, I have a batch file in BATCHHOME that does something to a single txt file and I want to produce a batch file that will process all the txt files in a given directory. The lone echo in the loop is to better illustrate the problem.
Now, here's where I have a problem. The output of this looks like:
processing foo\text1.txt
some output from batch.bat
ECHO is on.
C:\somedir>(
echo processing foo\text2.txt
"C:\the\path\of\batch.bat" the arguments here foo\text2.txt
)
ECHO is on.
C:\somedir>(
echo processing foo\text3.txt
"C:\the\path\of\batch.bat" the arguments here foo\text3.txt
)
ECHO is on.
(etc)
Ok... I don't know why the batch file I'm calling turns echo on, but I didn't make it, so I'll just turn it back off each time! I changed the last part to:
:callbatch
for %%f in (%dir%\*.txt) do (
echo processing %%f
"%BATCHHOME%\batch.bat %args% %%f
echo off
)
echo
echo on
echo
echo Finished!
(Again, the two lone "echo" are there for debug) So now the output looks like this:
processing foo\text1.txt
some output from batch.bat
processing foo\text2.txt
some output from batch.bat
processing foo\text3.txt
some output from batch.bat
(etc.)
ECHO is off.
ECHO is on.
Finished!
This would be almost perfect, but there's something a bit odd. If echo is on, then why does it display "Finished!" instead of "echo Finished!"? The bigger (but related) problem however is that when the batch file is done, I don't get my path displayed any more. In other words, instead of having:
C:\Somedir>_
I just get
_
I need to type "echo on" manually to get the path to show again. Where did I go wrong?
edit: Just to clarify, I am aware that "echo" by itself prints the current status of echo. That is what I intended. In the first code, they are there to show that echo mysteriously turns on after I call the other batch file. In the second one, it is there to show that echo is on at the end of the batch file, yet the behaviour is as if it wasn't. THAT is my problem.