[Toc][Index]

Internal Variables


Internal variables are special environment variables built into CMD.EXE to 
provide information about your system.  They are not actually stored in 
the environment, but can be used in commands, aliases, and batch files 
just like any other environment variable. The values of these variables 
are stored internally in CMD.EXE, and cannot be changed with the SET, 
UNSET, or ESET command.  However, you can override any of these variables 
by defining a new variable with the same name. 
The list below gives a one-line description of each variable, and a 
cross-reference which selects a full screen help topic on that variable. 
Most of the variables are simple enough that the one-line description is 
sufficient.  However, for those variables marked with an asterisk [*], the 
cross-reference topic contains some additional information you may wish to 
review.  You can also obtain help on any variable with a HELP variable 
name command at the prompt (this is why each variable has its own topic, 
in addition to its appearance in the list below). 
See the discussion after the variable list for some additional 
information, and examples of how these variables can be used.  For 
additional examples, see the EXAMPLES.BTM file which came with CMD.EXE. 

The variables are: 
Hardware status 
        _CPU            CPU type (86, 186, 200, 386, 486, 586) 
        _MONITOR        Monitor type (mono or color) 
        _NDP            Coprocessor type (0, 87, 287, 387) 
        _VIDEO          Video board type (mono, cga, ega, vga, xga, 8514, 
                        or IA/A) 
 
 Operating system and software status 
        _ANSI           ANSI status (always 1 in CMD.EXE) 
        _APMAC          * APM AC line status 
        _APMBATT        * APM battery status 
        _APMLIFE        * APM battery life 
        _BOOT           Boot drive letter, without a colon 
        _CI             Current cursor shape in insert mode 
        _CO             Current cursor shape in overstrike mode 
        _CODEPAGE       Current code page number 
        _COUNTRY        Current country code 
        _DOS            * Operating system (DOS, OS2, etc.) 
        _DOSVER         * Operating system version (2.1, 3.0, etc.) 
        _KBHIT          Keystroke waiting in buffer (0 or 1) 
        _MOUSE          Mouse driver flag (always 1 in CMD.EXE) 
 
 Command processor status 
        _4VER           CMD.EXE version (3.03, 3.04, etc.) 
        _BATCH          Batch nesting level 
        _BATCHLINE      Current line number in current batch file 
        _BATCHNAME      Name of current batch file 
        _CMDPROC        Command processor name 
        _DNAME          Name of file used to store file descriptions 
        _HLOGFILE       Current history log file name 
        _LOGFILE        Current log file name 
        _PID            CMD.EXE process ID (numeric) 
        _PIPE           Whether running in a pipe 
        _PPID           Parent process ID (numeric) 
        _PTYPE          OS/2 session type (AVIO, DT, FS, PM) 
        _SHELL          Shell level (0, 1, 2, ...) 
        _SID            Current OS/2 session ID 
        _TRANSIENT      * Transient shell flag (0 or 1) 
        _WINTITLE       Current window title 
 
 Screen and color 
        _BG             Background color at cursor position 
        _COLUMN         Current cursor column 
        _COLUMNS        Screen width 
        _FG             Foreground color at cursor position 
        _ROW            Current cursor row 
        _ROWS           Screen height 
        _XPIXELS        Physical screen horizontal size 
        _YPIXELS        Physical screen vertical size 
 
 Drives and directories 
        _CWD            Current drive and directory (d:\path) 
        _CWDS           Current drive and directory with trailing \ 
                        (d:\path\) 
        _CWP            Current directory (\path) 
        _CWPS           Current directory with trailing \ (\path\) 
        _DISK           Current drive (C, D, etc.) 
        _LASTDISK       Last possible drive (E, F, etc.) 
 
 Dates and times 
        _DATE           * Current date (mm-dd-yy) 
        _DAY            Day of the month (1 - 31) 
        _DOW            Day of the week (Mon, Tue, Wed, etc.) 
        _DOWI           Integer day of the week (1 = Sunday, 2= Monday, 
                        etc.) 
        _DOY            Day of the year (1 - 366) 
        _HOUR           Hour (0 - 23) 
        _MINUTE         Minute (0 - 59) 
        _MONTH          Month of the year (1 - 12) 
        _SECOND         Second (0 - 59) 
        _TIME           * Current time (hh:mm:ss) 
        _YEAR           Year (1980 - 2099) 
 
 Error codes 
        ?               * Exit code, last external program 
        _?              * Exit code, last internal command 
        _SYSERR         * Last OS/2 error code 
 
 Compatibility 
        =               * Substitutes escape character 
        +               * Substitutes command separator 
 
 
 Additional Notes 
 These internal variables are often used in batch files and aliases to 
 examine system resources and adjust to the current computer settings. 
  You can examine the contents of any internal variable (except %= and %+) 
 from the command line with a command like this: 

 
         [c:\] echo %variablename
 
 
 On disk volumes which do not support long filenames, variables which 
 return a path or file name will return their result in upper or lower 
 case depending on the value of the SETDOS /U switch or the UpperCase 
 directive in the .INI file.  On volumes which do support long filenames, 
 these variables will return names as they are stored on the disk and no 
 case shifting will be performed.  Returned filename values which include 
 long filenames are not quoted automatically; you must add quotes yourself 
 if they are required for your use of the variable value (see Argument 
 Quoting). 
 Some variables return values based on information provided by your 
 operating system.  These variables will only return correct information 
 if the operating system provides it.  For example, _APMBATT will not 
 return accurate results if your operating system and Advanced Power 
 Management drivers do not provide correct information on battery status 
 to the command processor. 
 
 Examples 
 You can use these variables in a wide variety of ways depending on your 
 needs.  Here are just a few examples.  For additional examples, see the 
 EXAMPLES.BTM file which came with CMD.EXE. 
 Some of these examples rely on the IF and IFF commands to test the value 
 of a variable and perform different actions based on that value. 
 In a batch file, set the color based on the video card type: 

 
         iff "%_video"=="mono" then
           color bright white on black
         else
           color bright white on blue
         endiff
 
 
 Store the current date and time in a file, then save the output of a DIR 
 command in the same file: 

 
         echo Directory as of %_date %_time > dirsave
         dir >> dirsave
 
 
 Set up a prompt for the primary shell which displays the time and current 
 directory, and a different one for secondary shells which includes the 
 shell level rather than the time (see PROMPT for details about setting 
 the prompt).  Also set different background colors for the two shells, 
 without changing the foreground color.  You might use a sequence like 
 this in your 4START file (see Automatic Batch Files): 

 
         iff %_shell==0 then
           prompt $t $p$g
           color %_fg on blue
         else
           prompt [$z] $p$g
           color %_fg on cyan
         endiff
 
 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs