Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cmd file exit code

Status
Not open for further replies.

piti

Technical User
Apr 12, 2001
627
SK
hi

anyone here who can tell me how to make a cmd file return an error code (exit with error) when some condition is met, e.g. a file does not exists, ...
thanx
 
have you tried pointing it to a text file? Im assuming the CMD code runs too quickly to see the results for you..

next time you run the code, try:
c:\>programname.exe > c:\results.txt

..substituting "programname.exe" for whatever file you're executing.
Pbxman
Systems Administrator

Please let Tek-Tips members know their posts were helpful.
 
If the cmd is started from a batch- or script file,
the internal variable ERRORLEVEL may be tested,
and various actions taken.
 
Put your .EXE or .COM in a batchfile, FRED.BAT or whatever, and on the next line put PAUSE. Then when you run the batchfile it will stop after running the application and invite you to "Press any key to continue...".

ROGER - GØAOZ.
 
well actually i have a batch file (program.cmd) and i want this batch file exiting with error if some of the conditions tested there is true
 
to better explain
i'm running that batch from mssql server job and would like not to run the following steps when something goes wrong during the execution of the batch
 
Ok. Well, as P Andersen (above) suggests, depending upon what comes back from running your prog, maybe the internal ERRORLEVEL response can be used to direct your batch commands to an appropriate "label" within the batchfile. This could then produce a simple menu offering whatever options you want. I.e. Try again, quit, etc. I wrote a simple one in NT4 recently for someone which attempted to make a network connection from his laptop to his main machine and XCOPY some of his files over. If it couldn't make the connection the batch command diverted to a label which typed on screen "No connection to Server" and options to quit, try again etc.

Hope that helps...

ROGER - GØAOZ.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top