I wonder if someone can help me in DOS batch command script.
The script will run two applications i.e. app1.exe, and app2.exe. First app1.exe will run and once app1.exe has finished running then the app2.exe will run.
(Please know app1.exe must finish running before app2.exe will start)
Regards.
Use "call"
call app1.exe
call app2.exe
You can force a sequence of programs by using
#echo off
start /WAIT /B app1.exe
start /WAIT /B app2.exe
/B means that the new app will be started without creating a new window.
Related
I have a script that will call other scripts to run then go back to process.
Example:
Call a script to ping and when it completes, go back to script.
My issue is I have a script called Bounce.bat
Here is the code:
#Echo off
set IPADDRESS=127.0.0.1
set INTERVAL=60
:PINGINTERVAL
ping %IPADDRESS% -n 1
timeout %INTERVAL%
GOTO PINGINTERVAL
What I need is the command that will kill the Bounce.bat from inside another batch script.
I was going to try killing CMD but that kills the original script as well.
I Have tried experimenting as well as looking at script examples.
Does anyone know what is needed to kill this bat only?
You can use the Command "taskkill" to stop other processes in Windows.
You can write something like this in your other batch-file:
taskkill /IM MYBATCHFILENAME.bat
You can force to kill the process, if you are using the parameter /f at the end of your command.
I'm trying to create a batch script to install a particular program via SCCM (eventually).
Currently I'm just trying to get it to run on my own machine but running into to one or two problems.
The Installation as a manual process is a pain, needs to run 1 prerequisite EXE, then once finished run the main EXE. The process should then wait for that to finish before running the program itself and to be left open for 30 seconds (roughly) then kill that task. Lastly, I need to copy some config files over.
Typing individual lines manually works but struggling for an all in one solution. I've tried using timeouts, PAUSE, && - all seems to be failing to sequence the tasks one after the other.
vstor_redist.exe /q /norestart
&& APP.exe /Silent
&& cd "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\APP" "Shortcut.lnk"
&& taskkill /IM "APP.exe" /F
&& xcopy "config.config" %AppData%\COFIG\*.* xcopy "config.xml" %AppData%\CONFIG\*.*
I have found that I was able to achieve my goal by using the Start command with its /Wait option.
Example:
start /wait app.exe
start /wait app2.exe
And so on
What I got is a list of bat files:
file1.bat
file2.bat
…
file29.bat
I need them to run one after each other. Meaning when the file1.bat closes file2.bat starts and so on.
I tried this, but it doesn't work properly:
start /wait call file1.bat
start /wait call file2.bat
You might want to add more to your question to make it easier to understand. My guess is that you want the bat file to open the next one then close itself after that.
If that's what you want to do; add these commands to each of the files:
start file2.bat
exit
Of course, you'll want to change start file2.bat to start file3.bat and so on for each file.
If you want file1.bat to manage all of the files, I don't think that's possible in batch.
You didn't describe how exactly it's not doing what you expected. I'm guessing that what happens is you're having to shut down each script before the next one will continue.
Documentation on start says:
WAIT Start application and wait for it to terminate.
command/program
If it is an internal cmd command or a batch file then
the command processor is run with the /K switch to cmd.exe.
This means that the window will remain after the command
has been run.
If you must use start then you could force it to use the /c switch which will automatically close the window once it's done:
start /wait cmd /c call file1.bat
I'm not really sure you accomplish anything by using call so that ought to be equivalent to just:
start /wait cmd /c file1.bat
Using start creates a new window for each program and you may just want to have it all run in a single command processor window.
As noted by Biffin you can just list them all out in a master script and they will run in order.
call file1.bat
call file2.bat
...
call file29.bat
And a shorthand for that is:
for /l %%f in (1; 1; 29) do call file%%f.bat
Remember to double up those percent characters inside a batch script but not on the command line.
This question might explain some of the unexpected behavior you were seeing.
How to run multiple .BAT files within a .BAT file
I tried to put this into a example.bat call= blahblah.exe call= example.bat /wait blahblah.exe
but the above does not wait, it will call the example.bat as soon as the blahblah.exe runs.
I want to start the example.bat when the WHOLE blahblah.exe has finished. thanks
You can use start. If you wanted to run a.bat, execute b.exe then run c.bat when it exits;
a.bat:
start /wait b.exe
call c.bat
Quick and simple question: I have a batch file that calls for some .exe like so:
START /WAIT GVE %opt%
My problem is that the program starts in a new console, is their anyway to make it start in the same console ? I've tried /NOCONSOLE option without success.
Thanks
I think you just need the /B option (assuming the exe is a console app)
start "" /b /wait gve %opt%