?
Solved

DOS batch script which makes use of a call function to call another batch script

Posted on 2014-11-21
6
Medium Priority
?
253 Views
Last Modified: 2014-12-06
I need a DOS batch script which calls another batch script, but need conditions in the script to make sure:-

1) the script calls the other batch script successfully
2) the script exists if the script fails

Thanks
0
Comment
Question by:rakkad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 40457392
@echo off
if exist OtherBatch.cmd  (
  call OtherBatch.cmd || echo This is an error
) else (
  echo Script not found
)

Open in new window

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1500 total points
ID: 40457393
Try something like this... is that what you mean?

Steve

@echo off
REM change to current directory of this batch file, mapping drive if needed for a UNC
pushd "%~dp0"
  if not exist 2.cmd (
    echo The batch file was not found, exiting
    exit /b
  )

  call 2.cmd 2>NUL

  if errorlevel 1 (
    echo The other batch file was found OK and the error level was %errorlevel%
    exit /b
  ) ELSE (
    echo The other batch file was found OK and showed no error
  )

popd

Open in new window


and the second batch file then you can return the error code to the first with exit /b 1 etc., i.e.

exit /b 0 = OK
exit /b 1 = returns 1
exit /b 2 = returns 2
exit /b %errorlevel% = returns the errorlevel of the command before it

@echo off
echo Do your stuff here in batch 2
echo An error level returned on the exit statement as you need:

exit /b 1

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40457399
Crossed posts there with Qlemo of course... basically the same difference but I laid mine out a bit more wordily to show you other options.

Steve
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Closing Comment

by:rakkad
ID: 40483246
This task worked
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40484092
Why just a B grade?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40484607
Why only Steve got points (and why a "B" grade only)? Both solutions are comparable and without much of a difference.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

800 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