Solved

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

Posted on 2007-12-03
3
1,894 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:
Richard Quadling 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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