The Lost Art of Batch Programming

No matter what other interesting skills you acquire, an ability to write DOS batch files is a skill that you will cherish throughout your life. And should you survive to a hundred and five, batch programs may be the one thing that remains unchanged.

Piping, Pinging, setting the path, echoing.... all the good stuff...

Here's an example of using a batch program to stop an application (CALC.exe in this case) from being run twice on the one machine.


@ECHO Off
IF EXIST C:\%COMPUTERNAME%.txt GOTO RUNNING
ipconfig > C:\%COMPUTERNAME%.txt
ECHO PROGRAM STARTED...
CALC.EXE
ECHO PROGRAM FINISHED
IF EXIST C:\%COMPUTERNAME%.txt DEL C:\%COMPUTERNAME%.txt
GOTO END
:RUNNING
ECHO FILE IS ALREADY RUNNING
:END

This example used the following:

  • @
  • ECHO
  • ENVIRONMENT VARIABLES (%COMPUTERNAME%)
  • IF
  • EXIST
  • GOTO
  • REDIRECTION (>)
  • DEL
  • LABELS (:)
 

My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.