Creating Customized Batch Files

Home Forums Knowledge Base Legacy Applications Creating Customized Batch Files

  • This topic has 0 replies, 1 voice, and was last updated 19 years ago by Rob.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1665
    Rob
    Member

    Creating Customized Batch Files

    Every once in a while I run across a situation where I want to shell out to a DOS command or DOS batch file but I need to pass it a variable. TouchPro’s shell can be configured to write the variables in a special text file, but if I am just using DOS commands in my shell, I have no way to get the variable value out of that file. What to do, what to do? …..

    The answer is to build a batch file on the fly using print templates which can have variables embedded within them, then execute the batch file. To accomplish this, we will have to pull several tricks out of our hat. As a hypothetical situation, let us assume that we want to be able to back up today’s journal file to a backup directory at the push of a button. Since this is only hypothetical, let us further assume that we want to back up the timekeeping file to a different directory. Why would we do this? Hey, I said it was a hypothetical situation, okay?
    How To Do It

    1. Create a print template called BACKDATA with these lines:

        CD..REPORTS
        COPY ######.JOU BACKUPJOURNAL
        COPY ######.TIM BACKUPTIMEKPNG
        CD..

        Note: Use Date(2) for ######, and be sure to turn off the Require PLU’s option.

    2. Create a batch file called BACKDATA with these lines:

        @ECHO OFF
        CD DATA
        COPY BACKDATA.PRN BACKDAT2.BAT /Y
        ERASE BACKDATA.PRN
        CALL BACKDAT2
        CD..

    3. Create a shell called BACKDATA with these settings:

        * Working Directory – blank
        * Command Line – BACKDATA
        * Video – Preserve Screen

    4. Define a printer in Printer Definitions called BACKDATA and set it as type File.

    5. Create a button labeled Backup Today’s Data and put these commands on it:

        Do Template BACKDATA
        Print to BACKDATA
        Shell to BACKDATA

        How It Works

    This trick always reminds me of the game Mouse Trap. The crank turns the wheel which pulls back the shoe which kicks the bucket which makes the marble roll down the ramp, which…… well, you get the idea. Pressing the Backup Today’s Data will trigger the following:

      1. The Do Template command creates the correct DOS command to copy today’s files, placing the value of Date(2) in the appropriate places.
      2. The Print To command sends the output to a file in the DATA subdirectory called BACKDATA.PRN.
      3. The Shell To command executes the batch file called BACKDATA.
      4. The batch file converts the PRN file to a second batch file called BACKDAT2, then executes it.
      5. BACKDAT2 copies today’s journal and timekeeping files to a backup directory.
      6. BACKDAT2 completes and returns control to BACKDATA, which returns control to the shell, which returns control to the program. Whew!

    This may seem like a lot of work to accomplish a simple task, but ultimately it can give you an extremely powerful tool, illustrating the flexibility and capability of TouchPro. Once again it illustrates that the only limits are set by the designer’s imagination and ingenuity.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.