Solved

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

Posted on 2014-11-21
6
251 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 69

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 500 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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 69

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve 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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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