running multiple exe through batch file - batch-file

Experts, I am trying to run a bat file using the below.
start /wait "D:|Silent_installer.bat"
start /wait 'D:def.bat"
It's happening like both bat files running at the same time.
But I wanted the first bat file to run completely then def.bat should start. The first bat file takes approx 60 min and inbetween second bat file starting.Ideally I wanted the first batch to complete 100% then second bat file should start.
I also used call like below but no luck
call "abc.bat"
call "def.bat"
Any suggestions would be of great help

You have to use start "" /wait command with the program in the abc.bat file itself. One of the programs being used inside abc.bat is multi-threaded and lets the batch file end before it finishes.

why not simply
"abc.bat"
"def.bat"
in your batch file ?

You could use Start command to start application

Ok. Two points here.
The start command is used for asynchronous execution, so if you " wanted the first batch to complete 100% then second bat file should start", just don't use it!
In order to execute two Batch files from inside another one, you must use call command as you show us in your question, that is:
.
call "abc.bat"
call "def.bat"
Perhaps if you explain what "I also used call like below but no luck" means, we may help you in a better way.
PS - Did you realized that your first example
"D:|Silent_installer.bat"
contain an invalid character | in the name of the Batch file?

Related

Cannot run batch file with xcopy command

The code in batch file is :XCOPY "D:\hosts" "C:\Windows\System32\Drivers\etc" /R /Y. But it doesn't work. cmd run like :
How do I fix this?
Based on the output, I'd say you've called your batch file xcopy.cmd or `xcopy.bat.
That means, when it tries to call the actual xcopy executable, it instead calls itself in an infinitely recursive loop.
If that is the case, you have a couple of options:
Rename your batch file to something more sensible, such as copy_hosts.cmd, something that's not likely to clash with a real command; or
Make sure you call xcopy.exe explicitly from your batch file, so it goes and gets the real one.

can we use multiple "cd" commands in a batch file?

I was not able to add multiple change directory commands in a single batch file:
cd C:\abc\def
do something
cd C:\def\ghi
do something
It stops in the second line, and does not come back to execute the third line.
Yes you can.
I am betting that what you're doing in step 2 is calling another batch file, without using the call keyword.

Run batch files sequentially

I want to ask you all how to run batch files sequentially in Windows.
I have tried :
start /w batchfile_1.bat
start /w batchfile_2.bat
..
start /w batchfile_n.bat
but I have to close the previous .bat file process manually (e.g. by clicking) before continuing into the next one.
Is there any solution to do this automatically without me doing the manual closing previous .bat program every time?
Thanks a lot.
I would check the solutions to this question: Run Multiple batch files
Taken from the answer in the link.
Use call:
call bat1.cmd
call bat2.cmd
By default, when you just run a batch file from another one control will not pass back to the calling one. That's why you need to use call.
Basically, if you have a batch like this:
#echo off
echo Foo
batch2.cmd
echo Bar
then it will only output
Foo
If you write it like
#echo off
echo Foo
call batch2.cmd
echo Bar
however, it will output
Foo
Bar
because after batch2 terminates, program control is passed back to your original batch file.
If you are in love with using START, you could have your batch files end with the EXIT command. That will close the windows created by the start command.
#echo off
.
.
:: Inspired coding
.
.
exit
I'm not sure but based on your comments, the following seems to be happening when you run that sequence of START commands:
A START /W command is invoked and starts a batch file.
The batch file starts executing and runs a program.
The batch file finishes and its console window remains open, but the program continues running.
The START /W command that was used to run the batch file is still executing because the console window remains open.
You wait until the program terminates, then you close the console window, and then the next START /W command is invoked, and everything is repeated.
Now, if you place EXIT at the end of every batch file you want to run sequentially, that makes situation worse because it causes the console window to close after the batch script completes, and that in turn ends the corresponding START /W command and causes another one to execute, even though the program invoked by the batch script may still be running. And so the effect is that the batch scripts (or, rather, the programs executed by them) run simultaneously rather than sequentially.
I think, if this can be solved at all, you need to move the START /W command and put it in every batch file in front of (every) command that that batch file executes and doesn't wait for the termination of. That is, if your batchfile_1.bat runs a program.exe, change the command line to START /W program.exe, and similarly for other relevant commands in other batch files.

Batch file stops running after the first command

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.
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
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.
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.
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.

Batch script stops after first call to other batch script

I'm attempting to execute a batch script that currently looks like this:
D:
cd D:My Documents\FtpSolution\Test
getftp.bat
call delimconvert.exe
call convert-to-xls.bat
However this stops dead after getftp.bat has run.
What am I doing wrong? It's important that these commands all run sequentially.
Use call:
Calls one batch program from another.
CALL [drive:][path]filename [batch-parameters]
batch-parameters Specifies any command-line information required by the
batch program.
If you invoke other batch files without call then control is passed to them but not back again (which is what call changes).
use start command to launch it in a new window.
start /wait getftp.bat
Try using "Goto :EOF" rather than "exit" at the end of the batch file that you're calling - in your case, the getftp.bat file...
That's what fixed mine - tested on Win10 enterprise.

Resources