Click here to Skip to main content
Click here to Skip to main content

Program Error Reports with Visuals from .bat Files (Win7)

, 12 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Program return values inspected by .bat files with visual feedback

image from wikipedia : Ascii Art

<-- The Command Line Is Awesome!

This tip/trick is basically a short batch script example of a friend for the programmer who has to use other peoples tools, batches, programs in order to confirm whether everything went well with the external tools. Smile | :)

This revolves basically around inspecting what a .bat file (or possibly .exe files too) returns as the value after it has been run, (i.e., whether it succeeds or not) then reporting about any possible errors or successes in a visual way, so that any errors that the user of a batch script file could normally miss, won't be missed. Smile | :)

 

Why Use This?

Because in everyday work around computers, there are multiple EXEfiles, batch files, etc. that might come in play, some regularly, some maybe not so regularly, and this is a fun trick how to inspect whether those batch files did their job properly or not. Smile | :) Mostly, this is useful for people that use some set of external batch files to do some operations, but in case you are not one of those, it can still be a fun experience to download the articles sample and try it out on your Windows machine. Smile | :)

Using the Code

usage: download the sample (coolbatchaction.zip)or follow the next instructions:
1. create a do_something_cool.bat that's empty
2. create another .bat file with the below script copy pasted in, save it as whatever.bat
3. then run whatever.bat and see what happens! ...or you can just download the sample ;)

Here's the body of the whole script:

@echo off
echo ---------------------------------------------------------------
echo .
echo .
echo . DOING SOMETHING IMPORTANT
echo .
echo .
echo ---------------------------------------------------------------

CMD /c do_something_cool.bat
IF %ERRORLEVEL% == 0 (GOTO ITSALLGOOD) ELSE (GOTO GURUMEDITATION)
 
:ITSALLGOOD 
echo ---------------------------------------------------------------
echo .
echo .
echo . That important thing went great! Happy time! :)
echo .
echo .
echo ---------------------------------------------------------------
mshta "javascript:var sh=new ActiveXObject( 'WScript.Shell' ); sh.Popup( 'THE THING SUCCEEDED!', 0, 'do_something_cool.bat', 64 );close()"
exit
 
:GURUMEDITATION
echo ---------------------------------------------------------------
echo .
echo .
echo . Something went wrong bro! You gotta meditate on this!
echo .
echo . Write exit to confirm and close after you've fixed it ;)
echo .
echo .
echo ---------------------------------------------------------------
mshta "javascript:var sh=new ActiveXObject( 'WScript.Shell' ); sh.Popup( 'THE THING FAILED, PLEASE FIX!', 0, 'do_something_cool.bat', 64 );close()"
cmd /K ping 127.0.0.1 -n 1 -w 1000 > nul

Points of Interest

The mshta JavaScript command line feed opens up some interesting opportunities for various smart snippets on Windows, that could be looked into more. Smile | :) Also, the %ERRORLEVEL% is an interesting builtin.

History

  • Version 0.01 uploaded, 12th of June 2014

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jani Mäkinen
Software Developer (Senior) Frozenbyte
Finland Finland
I've programmed since the 90's QBasic times and love programming tight and slick code.
 
Here are some links for my 'off the clock' programming: http://www.gfx0.com
 
Specialties: C, C++, Game Programming
 
I was born in the middle of Finland into a small farming town. Moved to Helsinki, then to Germany and am now back in Helsinki programming as my dayjob in the Game Industry Smile | :)
Follow on   Twitter   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 12 Jun 2014
Article Copyright 2014 by Jani Mäkinen
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid