run a utility, then make a decision on the result returned

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Lyle
Posts: 1
Joined: 20 Sep 2011 18:19

run a utility, then make a decision on the result returned

#1 Post by Lyle » 20 Sep 2011 18:38

In Windows 2008, I'm trying to write a batch file that runs a Windows utility.
In one case, the utility returns silently, and the batch file should return a success condition.
In the other case, the utility returns one or more lines of status info, and the batch file should return an error condition.

In Batch scripts, I'm not familiar with assigning the output of a utility to a variable, then testing it. In shell, I might use "wc -l".

Maybe the utility returns a return code in addition to some text output, and I can check the return code. Happy to test that, but don't know how to go about it.

Any thoughts, or pointers to batch documentation are appreciated.

Thanks...Lyle

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: run a utility, then make a decision on the result return

#2 Post by Ed Dyreen » 20 Sep 2011 18:54

Code: Select all

@echo off

start "nexist" "nexist.XEX"
if errorlevel 0 (
  echo.succes
) else (
  echo.failed
)

pause
exit /b

Post Reply