Solved

Run a .exe setup from a batch file and recieve its exit code

Posted on 2007-12-03
3
1,886 Views
Last Modified: 2009-01-11
Hi guys,

I have what I hope is a fairly easy question,

Basically I have a batch file which calls the setup.exe file for MSSQL and I would like to be able to detect if the setup ran successfully or abnormally terminated i.e the user canceled it.

Also would it be possible for the following:
1. bat file calls notepad.exe test.txt
2. test.txt doesn't exist, prompts user for creation of said file
3. user hit cancel
4. error code thrown and bat reports back

Any help you guys could provide would be great fully appricated.

Thanks
@ECHO OFF

cd c:\Documents and Settings\dev\Desktop\

start "" /wait setup.exe 

set SETUP_STATUS=%ERRORLEVEL%

echo %SETUP_STATUS%

if %SETUP_STATUS%==0 echo installation success

if not %SETUP_STATUS%==0  echo installation failed

Open in new window

0
Comment
Question by:Black_Omen
3 Comments
 
LVL 5

Expert Comment

by:TheGD
ID: 20505282
Your code seems to be work ok if setup.exe returns a exit code.

Notepad.exe normally does not return any exit code other than 0.
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 100 total points
ID: 21466998
Why not just detect the presence of the text file before running notepad?

Something like this ...
@ECHO OFF

IF NOT EXIST File.txt (

 SET /P CreateFile=File does not exist. Do you want to create it? [Y/N]

 IF /I "Y"=="%CreateFile%" GOTO CreateFile

 GOTO :EOF

)

:CreateFile

Notepad File.txt

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now