Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all

I am trying to build a batch file in which i want to open more 8 application at a time.
so i wrote this
echo off
cls
start /d "" firefox.exe http://www.ourgoalplan.com
start /d "" chrome.exe http://www.gmail.com
start /d "" iexplore.exe http://www.yahoo.com
start /d "" wlmail.exe
start /d "C:\Program Files\GNU\WinCvs 2.0" wincvs.exe
start /d "C:\Program Files\MySQL\MySQL Workbench 5.2 CE" MySQLWorkbench.exe
start /d "" VCSExpress.exe
start /d "" VWDExpress.exe

Its working fine but it takes more time because at a time 8 applications runs.
So i want to run the second application after the first application ends and the third one will execute after the second application end.

How to do the above requirement?
or Give me some suggestions ....

Please Help

Thanks In advance.
Posted
Comments
Sergey Alexandrovich Kryukov 30-May-12 12:38pm    
This question makes sense, my 5. I advise to use the answer by Richard; see also my last comment to his answer.
--SA
Richard MacCutchan 30-May-12 17:58pm    
Your comments are too kind. And we still don't know if the OP agrees.
bhagirathimfs 30-May-12 23:14pm    
Thanks SAKryukov and Richard MacCutchan

start /d "" firefox.exe http://www.ourgoalplan.com /wait

Typing start /? at the command line will give you all the command options.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 30-May-12 11:04am    
Perfect, just to the point, my 5.
I added my contribution, as a side dish, but very useful in general -- please see my answer.
--SA
Maciej Los 30-May-12 11:17am    
Good answer, my 5!
Tim Corey 30-May-12 11:23am    
The wait command waits until the process terminates. This means that the second process wouldn't start until the first one is closed (not just done loading). I didn't interpret that as being what the OP wanted. Am I missing something? It looks like the OP wants all eight apps open but doesn't want them to all try to load at once.
Richard MacCutchan 30-May-12 11:40am    
My reading of the question is that each application should not start until the previous one terminates (OP uses the word ends).
Tim Corey 30-May-12 11:50am    
See comment below (sorry, I keep forgetting to hit reply. :-)
In addition to the perfect answer by Richard:

The batch functionality has been considerably improved since DOS time, but for many people this fact remained unnoticeable. Even though batch language is too rudimentary and inadequate to many more or less complicated tasks, many innovations makes it acceptable for a solving of a pretty wide range of simple ad-hoc problem. Even subprograms with parameters and their calls with proper returns to the caller (not jumps) are now available. Here is one interesting batch file which helps to generate documentation on current-day help. You can use it for all your batch needs:

@ECHO OFF
IF "%OS%"=="Windows_NT" SETLOCAL DISABLEDELAYEDEXPANSION

:: Version number for this batch file
SET MyVer=1.40

:: Display "about"
ECHO.
ECHO AllHelp.bat,  Version %MyVer% for Windows NT 4 / 2000 / XP
ECHO Generate an HTML help file for "all" available commands
ECHO.
ECHO Note:
ECHO This batch file uses the redirected output of the HELP command to generate the
ECHO HTML file. Because some commands use "special" characters like ^&, ^<, and ^> in
ECHO their help screen, not all output is displayed correctly in the browser.
ECHO Known issues: skipped ^<space^> "tag" in CMD's special character list and skipped
ECHO \^<xyz and xyz\^> word position references in FINDSTR's output.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Improved white space handling by Johan Parlevliet
ECHO Further improvements for NT 4 by Ulf Lindb„ck
ECHO.
ECHO.
ECHO.

IF NOT "%OS%"=="Windows_NT" SET MyVer=
IF NOT "%OS%"=="Windows_NT" GOTO End

:: Store current code page and then set code page for European languages
FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%A) DO SET CHCP=%%B
CHCP 1252 >NUL 2>&1

:: Start writing HTML file
ECHO Writing HTML header . . .
> allhelp.htm ECHO ^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"^>
>>allhelp.htm ECHO ^<HTML^>
>>allhelp.htm ECHO ^<HEAD^>
:: Read Windows version using VER command
FOR /F "tokens=1 delims=[" %%A IN ('VER') DO SET Ver=%%A
FOR /F "tokens=1* delims= " %%A IN ('ECHO.%Ver%') DO SET Ver=%%B
:: Read latest Service Pack from registry
CALL :GetSP
>>allhelp.htm ECHO ^<TITLE^>Help for all %Ver%%SP% commands^</TITLE^>
>>allhelp.htm ECHO ^<META NAME="generator" CONTENT="AllHelp.bat, Version %MyVer%, by Rob van der Woude"^>
>>allhelp.htm ECHO ^</HEAD^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<BODY^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="Top"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<CENTER^>
>>allhelp.htm ECHO ^<H1^>%Ver%%SP% commands^</H1^>
FOR /F "tokens=* delims=" %%A IN ('VER') DO SET Ver=%%A
>>allhelp.htm ECHO ^<H3^>%Ver%^</H3^>
>>allhelp.htm ECHO ^</CENTER^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.

ECHO Creating command index table . . .
SET FirstCell=1
>>allhelp.htm ECHO ^<TABLE BORDER="0"^>
:: Skip 1 or 2 lines of HELP command's header
FOR /F "tokens=1 delims=[]" %%A IN ('HELP ^| FIND /N "."') DO IF %%A LEQ 2 SET Skip=+%%A
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
:: %Skip% skips 1 or 2 lines of HELP command's header
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispLine "%%A"
>>allhelp.htm ECHO ^</TD^>^</TR^>
>>allhelp.htm ECHO ^</TABLE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.

ECHO Writing help for each command:
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispFull "%%A"

ECHO Closing HTML file
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<DIV ALIGN="Center"^>
>>allhelp.htm ECHO ^<P^>This HTML file was generated by:^<BR^>
>>allhelp.htm ECHO ^<B^>AllHelp.bat^</B^>, Version %MyVer%
>>allhelp.htm ECHO for Windows NT^&nbsp;4^&nbsp;/^&nbsp;2000^&nbsp;/^&nbsp;XP^<BR^>
>>allhelp.htm ECHO Written by Rob van der Woude^<BR^>
>>allhelp.htm ECHO ^<A HREF="http://www.robvanderwoude.com"^>http://www.robvanderwoude.com^</A^>^</P^>
>>allhelp.htm ECHO ^</DIV^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^</BODY^>
>>allhelp.htm ECHO ^</HTML^>

ECHO.
ECHO An HTML help file "allhelp.htm" has been created and stored in the current
ECHO directory.
ECHO.
ECHO Now starting display of "allhelp.htm" . . .
START "AllHelp" allhelp.htm

:: End of main batch program
CHCP %CHCP% >NUL 2>&1
ENDLOCAL
GOTO:EOF


:: Subroutines


:DispLine
SET Line=%1
SET Line=%Line:(=^(%
SET Line=%Line:)=^)%
SET Line=%Line:"=%
SET Command=%Line:~0,8%
SET Command=%Command: =%
IF DEFINED Command CALL :DispCmdLine %Command%
FOR /F "tokens=1* delims= " %%a IN ('ECHO.%*') DO SET Descr=%%b
SET Descr=%Descr:"=%
>>allhelp.htm ECHO.%Descr%
GOTO:EOF


:DispCmdLine
IF "%FirstCell%"=="0" IF DEFINED Command (>>allhelp.htm ECHO ^</TD^>^</TR^>)
SET Command=%1
IF DEFINED Command (>>allhelp.htm ECHO ^<TR^>^<TH ALIGN="left" VALIGN="top"^>^<A HREF="#%Command%"^>%Command%^</A^>^</TH^>^<TD^>^&nbsp;^&nbsp;^&nbsp;^</TD^>^<TD^>)
SET FirstCell=0
SET Command=
GOTO:EOF


:DispFull
SET Line=%1
SET Command=%Line:~1,8%
SET Command=%Command: =%
IF DEFINED Command CALL :WriteFull %Command%
SET Command=
GOTO:EOF


:GetSP
SET SP=
:: Export registry tree to temporary file
START /WAIT REGEDIT.EXE /E "%Temp%.\%~n0.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
IF NOT EXIST "%Temp%.\%~n0.dat" GOTO:EOF
:: Read value of "CSDVersion" from temporary file
FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\%~n0.dat" ^| FIND /I "CSDVersion"') DO SET SP=%%~A
:: Check if value is valid
ECHO.%SP% | FIND /I "Service Pack" >NUL
IF ERRORLEVEL 1 SET SP=
DEL "%Temp%.\%~n0.dat"
:: Use a shorter notation
IF DEFINED SP SET SP=%SP:Service Pack=SP%
GOTO:EOF


:WriteFull
ECHO.  %1 . . .
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="%~1"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<H2^>%1^</H2^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<PRE^>
>>allhelp.htm HELP %1
>>allhelp.htm ECHO ^</PRE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A HREF="#Top"^>Back to the top of this page^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.
GOTO:EOF

:End


I'm really sorry that I cannot remember the source of this script, but its author Rob van der Woude and contributor Johan Parlevliet are written in the code, great thanks to them for this useful utility.

—SA
 
Share this answer
 
v4
Comments
Richard MacCutchan 30-May-12 11:11am    
Yes, very good; I think the two lines that read:

ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com

may give a clue as to the author.
Sergey Alexandrovich Kryukov 30-May-12 11:12am    
I fixed my text before I saw your note, we probably did it at the same time.
Thank you very much for the reference, I'll bookmark it this time.
--SA
Richard MacCutchan 30-May-12 11:12am    
See also Tim's reply.
Maciej Los 30-May-12 11:19am    
Wow! 5!
Sergey Alexandrovich Kryukov 30-May-12 11:28am    
Thank you, Maciej.
Not my work though; I just came across this thing; and it really helps me, on a regular basis...
--SA
You have a couple of options but none of them are going to be exactly what you would like. I don't know of a way to monitor a process to see that it has completed. However, you can put a "PAUSE" between each item, which will wait for the user to press any key for the batch to continue. That probably isn't ideal.

The other solutions involve a bit of hackery. Basically you do a network command that takes a known amount of time (ping, netsh, etc.) These can be used as delays. Probably the best is the ping, since you can determine how long to make the delay.

Here is an article with more information on how to do this:
http://www.robvanderwoude.com/wait.php[^]
 
Share this answer
 
Comments
Richard MacCutchan 30-May-12 11:12am    
See also SA's reply.
Tim Corey 30-May-12 11:22am    
Not sure what this means. Also, why the downvote (if that was you)? I guess it might be based upon how you determine what the OP wants, but this will start each application in order with a delay.
Richard MacCutchan 30-May-12 11:38am    
I was pointing to the foregoing answer by SA Kryukov, who also uses some information by Rob Van Der Woude.
Tim Corey 30-May-12 11:42am    
I understand he posted something from Rob Van Der Woude as well, but it wasn't foregoing. My answer was posted first (not being petty here, just pointing it out).
Richard MacCutchan 30-May-12 11:57am    
foregoing: totally the wrong word, but at my age randomness kicks in too often. I meant the one listed above yours.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900