The TCC-RT command processor is highly upwardly compatible with (and a replacement for) the default Windows command processor CMD.EXE. It is suitable for creating both simple and highly sophisticated batch programs. The language can also be used at the command prompt to create very powerful real-time manipulation of your computer.
TCC-RT has a huge set of capabilities. These capabilities are grouped into three categories:
• Internal Commands - These are the primary language constructs. Common commands include, DIR, COPY, MOVE, etc. TCC-RT gives you instant access to more than 230 internal commands. (Microsoft's CMD.EXE has fewer than 40 internal commands.).
Internal vs. External Commands
When we talk about an internal command, we mean the command is built into the Take Command program. With CMD, some commands, like XCOPY are actually separate programs. In PowerShell, the commands are generally external programs. PowerShell requires a separate .NET Framework to be installed on the computer for the commands to work.
• Internal Variable - Internal variables are special variables built into TCC to provide information about your system. They are not stored in the environment, but can be accessed as if they were environment variables in interactive commands, aliases, and batch files. Take Command provides more than 270 internal variables that can tell you a great deal about your computer and how it is operating. These include installed hardware, hardware status, operating system and software status, etc.
• Variable Functions - Variable functions are very similar to internal variables, but they take one or more parameters (which can be environment variables or even other variable functions). Variable functions are useful at the command prompt as well as in aliases and batch files to check on available system resources, manipulate strings and numbers, and work with files and filenames. There are more than 360 variable functions built into TCC-RT.
We are not going to talk about all of the features of the TCC-RT Language in this tutorial. (The manual is 1,300 pages long!) We are going to assume you know the basics of CMD and point you at a few of things that TCC-RT does better with less work than CMD.
There are several aspects of TCC-RT’s internal command set that are definitely worth looking at:
• Flow of Control Commands
• KEYSTACK Command
• HTTP and FTP
• Event Monitoring Commands (Triggers) -- We made this into a separate tutorial
Each of these is covered below:
Switches modify commands by giving them special instructions. TCC-RT has a superset of the CMD switches and is generally compatible. We say generally, because unfortunately, CMD has not been consistent from version to version.
For example, in CMD, the COPY command has 7 switches (XCOPY has more). The TCC-RT COPY command has 34 switches. Examples of a few of the switches that the CMD COPY command does not have include:
• /N Executes the copy command and shows you what the output would be, but does not actually execute the command
• /O Copy the source file only if the target does not exist
• /S Copy the subdirectory tree starting with the files in the source directory plus each subdirectory
• /H Copy all matching files including those with a hidden or system attribute set
• /W Delete files in the target directory that don’t exist in the source directory
These switches allow you to custom tailor the language in ways that you cannot do with CMD. They perform very powerful operations with only two or three keystrokes.
2. Flow of Control Commands
One of the weakest areas of CMD is flow of control. These are the constructs like IF..THEN..ELSE or DO LOOPS that allow you to develop sophisticated batch programs. If you are creating data center batch processes, the limitations in CMD keep you from doing anything sophisticated.
TCC-RT provides a very rich set of constructs that allow you to duplicate (or exceed!) the capabilities of the typical Linux shells.
The following examples shows some of the types of DO Loops you can create:
DO varname = start TO end [BY step]
DO WHILE condition
DO UNTIL condition
DO UNTIL DATETIME date time
DO FOR n [SECONDS | MINUTES | HOURS]
DO varname IN [range...] [/I:"text" /S[n] /A:[-|+]hsad] fileset
DO varname IN [/T"delimiters"] /L stringset
DO varname IN /C stringset
DO varname in /P command
DO varname IN @file
TCC also provides a very powerful IF..THEN..ELSE construct through the IFF command.
IFF condition1 THEN
[ELSEIFF condition2 THEN commandset2 ]
The alias in this IFF example checks to see if the parameter is a subdirectory. If so, the alias deletes the subdirectory's files and removes it (enter this on one line):
alias prune `iff isdir %1 then & del /s /x /z %1 & else & echo %1 is not a directory! & endiff`
This example shows how a SWITCH construct works. The batch file fragment below displays one message if the user presses A, another if the user presses B or C, and a third one if the user presses any other key:
inkey Enter a keystroke: %%key
echo It's an A
case B .or. C
echo It's either B or C
echo It's none of A, B, or C
KEYSTACK takes a series of keystrokes and feeds them to a program or command as if they were typed at the keyboard. (It has no equivalent in CMD.) KEYSTACK is most often used for programs started from batch files. For example, to start Word and open the last document you worked on, you could use the command :
start word & keystack /w54 alt-f "1"
This causes the following:
• Starts Word,
• The /w switch causes a delay of about three seconds (54 clock ticks at about 1/18 second each) for Word to get started,
• Places the keystrokes for alt-F (File pulldown menu), and 1 (open the most recently used file) into the buffer.
Word receives these keystrokes and performs the appropriate actions. Notice that the two commands, START and KEYSTACK are issued on a single command line. This ensures that the keystrokes are sent to Word's window, not back to Take Command.
4. FTP and HTTP
TCC-RT’s FTP and HTTP commands allow you to treat http and ftp sites as if they were local disk drives. This is a huge advantage over CMD. In Working in the Internet World, we show you how to use these commands to create practical remote monitoring applications.
In simplest form, you can act as if an FTP or HTTP site is a local disk. For example, to get a directory of the JP Software FTP site, you could use this command:
The following example shows how to include an ftp user name and password:
You can reference internet sites for DIR, COPY, MOVE, DEL and other commands. These commands also work with secure versions of FTP and HTTP.
5. Event Monitoring Commands (Triggers)
One of the most powerful features in TCC-RT are the event monitoring commands. They allow you to watch a wide variety of activities on your computer and “trigger” processes into action to deal with or report on issues.
This is described fully in Using Triggers in Take Command. It’s well worth the read.
Internal variables are special variables built into TCC-RT to provide information about your system. They are not stored in the environment, but can be accessed as if they were environment variables in interactive commands, aliases, and batch files.
There are more than 280 of them (CMD has less than 10). Key types of variables include:
• Hardware status
• Operating system and software status
• Dates and times
• Drives and directories
• Error codes
• Screen, color, and cursor
• Take Command status
Here is a simple example of how to use a common variable called _DOW (Day Of Week):
if "%_DOW" == "Mon" call c:\cleanup\weekly.bat
This example calls another batch file if today is Monday.
Before we go on...
A Quick Note:
One of the great mysteries of the command line is the % sign. What does it do? When you see a % sign in front of a variable or function, it means that the parser should evaluate the function and replace the variable or function with its text value. So, in the last example, %_DOW is replaced with the result, which in this case is MON, TUE or whatever.
How about something more real-time that you can run in the background:
if "%_BATTERYPERCENT" LT 25" MSGBOX Battery is low
This command will loop forever checking the battery status and popup a message box if the battery charge is getting low. MSGBOX is actually a very powerful command in TCC. Check it out in the help file.
Here is an example that checks to see if there are enough resources free before running an application.
iff %_GDIFREE lt 40 then
echo Not enough GDI resources!
Take a look at the list of internal variables by category in the help file.
Variable functions are one of the most powerful features of TCC-RT. Variable functions are very similar to internal variables, but they take one or more parameters (which can be environment variables or even other variable functions).
Variable functions are useful at the command prompt as well as in aliases and batch files to check on available system resources, manipulate strings and numbers, and work with files and filenames.
There are more than 380 Variable Functions grouped into 13 categories. They allow you to gather and manipulate system information in very powerful ways. (CMD has no variable functions.). Remember...they are all built-in.
•Dates and times
•Drives and devices
•Input dialog boxes
•Numbers and arithmetic
•Strings and characters
Using functions, TCC-RT can read and write text files, as well as some specialty files, such as the Windows Registry or .ini files. In the example below, we are going to read a .csv file called names.csv (which is a text file with fields separated by commas). The file looks as follows:
Our example will read this file a line at a time, and select the email address in each line. It will then echo them to the console.
do record in @%filename
set email=%@field[",",3,%record] echo %email
This code does the following:
• The first line of the example creates a variable with the full file and pathname of the .csv file using the @expand function.
• The second line uses a special case of the DO command to:
• Open the filename we set in the first line with an @filename function
• Create a line counter that it sets to one
• Set up a new variable called “record”
• Read the first line of text up to the CR and returns it to “record”
• The @field function picks the third field in the line (which contains the email address) using a “,” as the field delimiter and places it in a variable called “email”. The delimiter could be anything you wanted.
• The ECHO command outputs the email address to the console
• ENDDO returns the loop to the do statement, which increments the line counter to the next line. If it’s the end of the file, it terminates the loop.
This particular example seems sort of limited, but we use a variant of it to process our orders, construct registration keys and email them to our users with a remarkably small amount of code.