97

I am using the tool 'HTML Match' to compare two HTML files. As I have to compare many files, I create a batch file like the followion. For example, I give only five sets of files.

cd "C:\Program Files\HTML Match" HTMLMATCH.EXE "D:\Raj\compare1\a1.html" "D:\Raj\compare2\a1.html" "D:\Raj\compare_res\a1.html" HTMLMATCH.EXE "D:\Raj\compare1\a2.html" "D:\Raj\compare2\a2.html" "D:\Raj\compare_res\a2.html" HTMLMATCH.EXE "D:\Raj\compare1\a3.html" "D:\Raj\compare2\a3.html" "D:\Raj\compare_res\a3.html" HTMLMATCH.EXE "D:\Raj\compare1\a4.html" "D:\Raj\compare2\a4.html" "D:\Raj\compare_res\a4.html" HTMLMATCH.EXE "D:\Raj\compare1\a5.html" "D:\Raj\compare2\a5.html" "D:\Raj\compare_res\a5.html" 

When I execute this batch file in a cmd prompt, only the first line, that is, only 'a1.html', gets compared and produces a result. Then execution stops.

4 Answers 4

155

Add call in front of the commands you're running.

You can also change this to a for loop, so:

FOR /L %%i in (1,1,5) DO CALL HTMLMATCH.EXE D:\Raj\compare%%i%%\a%%i%%.html D:\Raj\compare%%i%%\a%%i%%.html D:\Raj\compare_res\a%%i%%.html 
Sign up to request clarification or add additional context in comments.

5 Comments

do u mean 'call' in front of every line i've given or just call xyz.bat ?
I mean call in front of every line you've written ( apart from probably the cd ).
the name of the file may change from this format to some other name . is there a way to read the file name if the folder path was specified and then execute it for each file name
Yes, the for loop will do that. Change what you need to. Type help for in a cmd window in order to find out what you need. Did adding call help?
Care to explain why, why wasn't it working in the first place?
88

The answer to your problem is to write CALL HTMLMATCH.EXE (and the rest of the parameters). Just use CALL in front of every executable command in the batch file.

4 Comments

I wrote my first batch file in something like 5 years today, and ran into this same problem. In case anyone is wondering, the reason adding "call" helps is because directly invoking a second batch file from within the first causes the second batch file to replace the first inside the interpreter. When the second batch file exits, the interpreter will have forgotten all about the original batch file you invoked. The call command causes the interpreter to keep track of where the invoking bbatch file left off, and return there when the called batch file exits.
@MarkBessey: Yes, you are absolutely right when invoking a second batch file from within the first one, but that is not the case here because the invoked program is an .EXE and it does NOT require the CALL!
This is true, but I think it's worthwhile to have solutions to related problems, since this is the result that comes up by searching here for the more-common issue. I also can't think of any other way that the described behavior would happen, so I wonder if the description is missing some detail.
@Aacini it seems that certain executables exit with a weird exit code that prevent the rest of a batch file to run, in which case the workaround to use CALL to run it in a different batch file works.
4

I was looking for something really similar and tried, I think, all the replies left here but I finally found the solution to my problem!!

In my script I want to check if one process is running, if not, start it (a .exe) and then check if another process is running, if not, start it too (but leave all the programs opened) and the problem is that the first .exe was started but then not moving to the second one because it was waiting until the process ended. It´s finally working for me with start and the magic comes with...

/separate

it works for me as:

start "program1" /separate program1.exe other commands 

Before it stopped after starting program1 because it was waiting until it was closed, I think, but this was not going to happen because I wanted to leave it opened. Now with the start /separate it continues with the other commands.

I found it in another forum but the thing is that it´s the manual, /separate is used to start in another memory space.

Comments

-1

You don't have to insert quotation marks where there isn't any space mark between.

Try that:

HTMLMATCH.EXE D:\Raj\compare1\a1.html D:\Raj\compare2\a1.html D:\Raj\compare_res\a1.html 

Maybe it will solve your issue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.