Start another batch file with multiple parameters with the start command? - batch-file

Is it possible to start another batch file and pass along multiple parameters with spaces, using the start command?
Here is how my program currently works:
main program starts > sees its outdated > calls updater (data1.exe) > updater copies new version over > It tries to delete the old version, but it can't. The old version is still marked as being used, from when it called the updater.
That's why the call command won't work. Do I need to use start then? How would that work?
This was the original line of code... the one that calls the updater and passes the variables along:
call "%dirofbatch%data1.exe" "%downloc%" "%dirofbatch%" "%lver%" "%lget%"
I'm stumped.
EDIT: I should mention that "data1.exe" is just an exe'd batch file.

How to read parameters in a batch file:
caller batch
start "" "%dirofbatch%data1.exe" "%downloc%" "%dirofbatch%" "%lver%" "%lget%"
called batch
set "parm1=%~1"
set "parm2=%~2"
set "parm3=%~3"
set "parm4=%~4"
echo %parm1% %parm2% %parm3% %parm4%

Related

running multiple exe through 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?

Why won't a batch file run when being called from within another batch file?

I have a batch file that first creates another batch file containing a ClearCase cleartool command and second, runs it:
ECHO cleartool lsactivity -long "%ACTIVITY%"^>"%OUTPUTFILE%">FILETORUN.bat
CALL FILETORUN.bat
When running the batch, FILETORUN.bat is generated with the correct format, but the CALL to it is completely ignored.
If I ECHO output after the CALL to a log file, I can see that the script just skips over it.
What could it be?
I have tried removing CALL but it makes no difference.
EDIT: SOLUTION
Thank you all for the input. I found the problem. Before the write to batch and batch call in the script there was a command that read information into a variable from a file:
SET /p FILETODELETE=<rmname_%CLEARCASE_USER%.tmp
It reads only the first line. For some reason this created a conflict with temporary batch file, and I have no idea why. I used a different solution for reading the first line from a file and the conflict doesn't happen anymore:
(set FILETODELETE=)
for /f "delims=" %%q in (rmname_%CLEARCASE_USER%.tmp) do if not defined FILETODELETE set FILETODELETE=%%q
If anyone can shed some light it would be great!
SET /P waits for user input, so it actually will finish the command with what you are trying to execute after that and consume the input buffer, which might produce different results on each machine.
See set command reference for more details

Why does calling a nested batch file without prepending "call" to the line exit the parent batch file?

I understand how to call nested batch files from within a parent file using the call command, as there are plenty of resources on that:
CALL
CALL (SS64)
Bat file termination
However, I don't understand why calling another batch file from another terminates the parent.
For a less abstract example, suppose I have a batch file that "links" together separate batch files, and I erroneously didn't prepend call to each line:
foo.bat
bar.bat
This would only execute foo.bat and then exit. To correctly execute both commands, I would have to prepend call before each statement:
call foo.bat
call bar.bat
Why does the first functionality still exist? Why hasn't it been changed? I noticed that call was introduced in MS-DOS 3.3, which was released in the late 1980s, so is this functionality still here for reverse compatibility?
I can't think of any (practical) usages of it, but perhaps I'm too used to "new" programming techniques.
DOS used simple text processing (back when you had things like FILES=20 in config.sys to allow 20 file handles), so opened the file, read the next line, closed the file, then executed the line just read. If the file called another, then the processing continued with that file, so only 1 file handle would be required for a batch file.
Until Microsoft put in the call command, there was no way to get back to the original file (without using tricks like giving the name of the previous file as a parameter, and using temporary files to let the original batch file know it had dome some processing, and could then GOTO the next part of the file).
As Sean Cheshire wrote, it's necessary for backward compatibility.
But starting a batch file from a batch file without using CALL does not terminate the parent!
It looks that way, as the parent normally will not executed further after the second batch exits.
But using a call before starting the second.bat, will show that the first batch isn't terminated.
parent.bat
echo parent.bat
call :myLabel
echo back in parent.bat main
exit /b
:myLabel
second.bat & echo back in parent.bat
exit /b
second.bat
echo second.bat
exit /b
I use here the the secpond.bat & echo back ... to avoid another bug/feature of cmd.exe.
If you use second.bat without any extras it will start second.bat AND jump to the label :myLabel in second.bat!
Call is basically saying "go execute this other batch file, and then come back here and continue". It has been there since DOS 3.3 or so, and if it were removed now would break all backward-compatibility (which is why people are still using batch scripts). It can also be used to branch to :link locations.
For info on the use and syntax (for future reference for others), you can see this MS TechNet link
If you need new functionality, use CMD scripts or PowerShell scripts instead.

Batch file not calling other batch files

I have a set of three automatically generated batch files, summed up below
arbitrary.bat
#ECHO OFF
set APPDATA=C:\Users\%USERNAME%\AppData\Minecrafts\1.9p5\
set T1=ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
set T2=³ÍÍÍ 1.9p5 ÍÍͳ
set T3=ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
masterControl
masterControl.bat
varInit
[main program logic...]
varInit.bat
set U=valueOfU
set P=valueOfP
set S=valueOfS
pause
The idea is that arbitrary.bat is run and the other two are called, as well. However, the program stops right after masterControl runs its first line (all lines in varInit are run successfully). **Why doesn't this program run past the first line of masterControl?
You have to use the command CALL to call each batch file from another i.e. CALL masterControl.bat

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