Question

Batch file to execute two .exe's

Asked by: Pro4ia

I need to create a batch file to execute two exe's (file1.exe & file2.exe).  These files are zip archives that self-extract.  The important thing here is that file1.exe needs to be unzipped first before file2.exe starts unzipping.  (It will show an error if file2.exe runs first or simultaneously with file1.exe)  What is the best way to create the batch file to execute these two files in order?

T.I.A.
John

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-06-15 at 11:10:08ID21887957
Tags

file

,

batch

,

exe

Topic

MS DOS

Participating Experts
12
Points
300
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. batch file to unzip to folder
    Hi, I have a zip file. I would like a batch file to unzip it to a new folder with the same name as the file, but without the zip extention. How do I do this? Thanks, Stoke
  2. Batch Unzip - Need Long Filename Support
    Is there an app out there that can unzip 3000 zip files in a batch process. I tried pkunzip from a command window but it doesn't support long file names. Any help would greatly be appreciated.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: leewPosted on 2006-06-15 at 11:11:51ID: 16913904

Just list them consecutively.  Batch files do not proceed until the each line is done executing.

file1.exe
file2.exe


 

by: OkigirePosted on 2006-06-15 at 11:19:31ID: 16913975

For future reference, sometimes an EXE file will halt the execution of the rest of the BATch file.  In otherwords, file1.exe will run and when it finishes, so does the batch file (and you never see file2 run).  In such a case, you would add CALL before it:

call file1.exe
call file2.exe

 

by: leewPosted on 2006-06-15 at 11:21:47ID: 16913989

Actually, call is used to call other batch files - you want to use start - but he doesn't want the execution to be simultaneous - they need to be sequential, so start will NOT be used in this case.

 

by: asyscokidPosted on 2006-06-15 at 11:23:20ID: 16914004

Doesn't CALL only work with batch files?  Wouldn't

start /Wait file1.exe
start /wait file2.exe

be better?

 

by: asyscokidPosted on 2006-06-15 at 11:25:05ID: 16914020

Missed the last comment.  Start /wait would be sequential.  I was never aware that batch files would run .exes to completion before proceeding.

 

by: leewPosted on 2006-06-15 at 11:25:24ID: 16914023

but start /wait is not necessary as batch files execute sequentially.

 

by: leewPosted on 2006-06-15 at 11:26:30ID: 16914038

Test it - make a simple batch file -

notepad
calc


then run it - calc will not run until you close notepad.

 

by: Pro4iaPosted on 2006-06-15 at 11:26:35ID: 16914040

I tried just using

file1.exe
file2.exe

and 2nd exe ran before first one finished and prompted me to run the first completely before running the second.  I guess it's just the nature of these self-archived zip exes.

Maybe I should use a timer instead or wait for a key to be entered after totally installing the first.

What do you guys think.

 

by: cwwkiePosted on 2006-06-15 at 11:31:18ID: 16914081

Do you know the last file from file1 which will be extracted?

then you can use just wait until that file exists.

 

by: leewPosted on 2006-06-15 at 11:33:07ID: 16914097

If that happened, then it's probably got one process spawning another then exiting, which would cause that behaviour.  If that's the case, you can try the start /wait but I suspect that won't work.  If it doesn't, you can get a sleep utility and do this:

file1
sleep 5
file2

The sleep command pauses the script for x seconds (in this example, 5).  
Sleep is part of the 2003 Resource Kit:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en

 

by: SteveGTRPosted on 2006-06-15 at 12:57:57ID: 16915010

If you knew what the program that was running is you could do the following:

@echo off

start notepad.exe

call :WAITFORAPP notepad.exe

REM notepad.exe

goto :EOF

:WAITFORAPP

tasklist /FI "IMAGENAME eq %~1" 2>&1 | findstr "No tasks running" >NUL
if ERRORLEVEL 1 goto WAITFORAPP

Good Luck,
Steve

 

by: dbruntonPosted on 2006-06-15 at 20:46:00ID: 16917483

Old dos batch files ran stuff sequentially until Win 95.  Not sure about NT batch files though.

Nowadays the commands run in parallel.

 

by: leewPosted on 2006-06-15 at 20:51:16ID: 16917514

Not true - like I said - test things - Simple batch file - notepad and calc.

 

by: mctiguePosted on 2006-06-26 at 18:06:11ID: 16989088

You could make two batch files.

The first one might be called batch1.bat, and the second one might be batch2.bat

The first one should look something like this:

@echo off
file1.exe
call batch2.bat
:end

The second one should look something like this:

@echo off
file2.exe
:end





 

by: paraghsPosted on 2006-07-01 at 01:33:35ID: 17022894

Try Delayexec :
http://www.rjlsoftware.com/software/utility/delayexec/

I created this batch file :
delayexec notepad 1
delayexec calc 20

and the batch file executed both the programs.
The reason could lie in this statement on its website :
"DelayExec will close after the file specified on the command line is launched."
So, once notepad is launched, first command of delayexec is completed, and the batch file executes second command.

Give it a try.

 

by: SunBowPosted on 2006-07-03 at 07:03:26ID: 17030977

asyscokid >  I was never aware that batch files would run .exes to completion before proceeding.

They don't. Or rather, they cannot be counted on to do that.

A running program can say "finished" any time to the calling program, but it is more of a delivery receipt than a read receipt or ompletion acknowledgement.

It depends on the programs used, and you'd best check them well, and their habits, to assess whether other workarounds are desireable.

With inside knowledge, one cheat is to know the habits of Program one. It extracts files. Cheat: what is the last file? Once you know that, (or force it at compilation) then you can just sit back and wait for it to show up. Adding a timer like timewait can be beneficial, holding up the return to batch continuation and counting up how long it takes while you are at it. You can later add an automated quit exit, for places you think it is simply taking too long.

 

by: SunBowPosted on 2006-07-03 at 07:11:57ID: 17031035

Pro4ia > Maybe I should use a timer instead or wait for a key to be entered after totally installing the first.

Sure, why not? Or, try to get independent output from file1 to the disk, for at least something like completion code or status. Then you can check the disk for it to show up, and continue on with the next script or whatever.

cwwkie > Do you know the last file from file1 which will be extracted? then you can use just wait until that file exists.

:-))

dbrunton >  Not sure about NT batch files though.

Exactly, NT will run in any order, thus the problem with inconsistent startups.

leew > If that happened, then it's probably got one process spawning another then exiting,  

:-))

 

by: mctiguePosted on 2006-07-10 at 09:53:32ID: 17074631

another thing you could try might be:

@echo off
file1.exe
pause
file2.exe
:end


That would make it so you would have to press a key before it executes the second exe.

 

by: xy8088Posted on 2006-07-19 at 14:27:43ID: 17141953

How about something like:

file1.exe
ping 127.0.0.1 -n 12
file2.exe

 

by: BillDLPosted on 2006-07-23 at 21:33:58ID: 17165368

John.
What version of DOS are you using (eg. Win98's version 7.10 command.com), or are you using Windows 2000/XP's "DOS" (cmd.exe)?
If using a Win9x DOS version, are you running the batch file from FULL DOS or from a DOS Window from within Windows?

I know that sounds a bit daft, but you haven't stated your OS nor whether your self-extracting *.exe files are 16-bit (eg. created with PKZIP or similar) or 32-bit GUI "dialog" types (eg. created with WinZip or WinRAR).

In addition to this, 32-bit "dialog" type self-extracting archives normally ask for user input unless executed with, or originally created to automatically use, the appropriate command line parameters to suppress the dialog and unpack silently.  

From my previous tests, batch files that are run from within Win9x's FULL DOS execute commands sequentially, whereas the same batch file run from a DOS Window WITHIN Windows 9x usually execute commands in parallel.  Windows XP executes them sequentially when run from a "command script" (*.cmd or *.bat) and the "Full DOS" scenario doesn't apply to XP anyway.
I don't know about Windows 2000 or 2003 in this respect.

Take a look at Windows XP   START /?

Quote:
"When executing an application that is a 32-bit GUI application, CMD.EXE DOES NOT wait for the application to terminate before returning to the command prompt.  This new behavior DOES NOT occur IF executing within a command script".

How about testing the errorlevel return code to ensure that the first job completed successfully and without errors before then proceeding to the next command?  I tend to regard that as a pretty important aspect to performing jobs like this.  Surely if something goes wrong while extracting the first .exe file, you DON'T want it to proceed to the next one?

Personally, I would tend to stick with the start /wait command and errorlevel tests just to be absolutely sure.  Something like this (assuming here that anything other than a Zero return code spells an error situation):

@echo off
start /wait file1.exe
if not errorlevel 0 goto :ERR1
goto :STEP2
:STEP2
start /wait file2.exe
if not errorlevel 0 goto :ERR2
goto :ALLOK
:ERR1
echo **** Warning: file1 did not unpack properly! ****
echo.
echo Press any key to terminate job ...
pause>nul
goto :ALLOK
:ERR2
echo **** Warning: file2 did not unpack properly! ****
echo.
echo Press any key to terminate job ...
pause>nul
goto :END
:ALLOK
echo ****** Job completed successfully *****
echo.
goto :END
:END
EXIT /B

I know it's a bit "blocky" and long-winded, but demonstrates my suggested approach.

 

by: BillDLPosted on 2006-07-23 at 21:42:02ID: 17165403

Sorry SunBow, I see now that you already mentioned "completion code or status".

Whoops, problem with a misplaced "ALLOK" label there after an error.  Revised version:

@echo off
start /wait file1.exe
if not errorlevel 0 goto :ERR1
goto :STEP2
:STEP2
start /wait file2.exe
if not errorlevel 0 goto :ERR2
goto :ALLOK
:ERR1
echo **** Warning: file1 did not unpack properly! ****
echo.
echo Press any key to terminate job ...
pause>nul
goto :END
:ERR2
echo **** Warning: file2 did not unpack properly! ****
echo.
echo Press any key to terminate job ...
pause>nul
goto :END
:ALLOK
echo ****** Job completed successfully *****
echo.
goto :END
:END
EXIT /B

 

by: BillDLPosted on 2006-08-16 at 16:02:58ID: 17330488

While I have the utmost respect for SteveGTR's exceptional and in-depth knowledge of working from the command line, there are issues here which I raised and asked earlier, and which have not been answered.  I asked what operating system the commands were to be used in and (if applicable) whether they were being run in Full DOS mode.

The answer to this is important, because Steve's TASKLIST command is not applicable to old DOS and Windows 9x.  Unfortunately Pro4ia has not returned to say whether he is running an OS that supports that command.  If not, then Steve's comment was nevertheless an excellent suggestion, and perhaps should then be better included in a points split with other comments that should have worked more universally.  We won't know for sure though until Pro4ia does return.  Hopefully he will come back with good news that SteveGTR's suggestion did work.

 

by: sirbountyPosted on 2006-08-16 at 16:37:02ID: 17330629

I agree BillDL - perhaps both yours (http:#17165368) & Steve's comment would be acceptable in a split, since they'd cover multiple scenarios between them...  

 

by: SteveGTRPosted on 2006-08-16 at 19:19:31ID: 17331248

We're working with incomplete information. Nothing regarding operating systems was given in the initial question.

In any case I have no problem with a split...

 

by: BillDLPosted on 2006-08-20 at 06:22:02ID: 17351319

Thank you, sirbounty, SteveGTR, and CetusMOD

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...