THE WELCH COMPANY
440 Davis Court #1602
San Francisco, CA 94111-2496
415 781 5700
rodwelch@pacbell.net


S U M M A R Y


DIARY: October 20, 2003 10:32 PM Monday; Rod Welch

Develop system environment variables for batch files in SDS.

1...Summary/Objective
2...SDS System Launch Batch Files Modified to Apply Windows Set Command
3...Subject Index Modify 035012 for Constructing Transfer Filename
4...035012 Load Transfer File for Subject Index Start Command Batch File


..............
Click here to comment!

CONTACTS 

SUBJECTS
DOS Environment Variables Windows 2000 Windows 98 SDS Batch Files an
Start Command Batch Operation Apply Windows Environment Variable to
Johnson, Gary DOS Environment Variables Windows 2000 Windows 98 SDS

1205 -
1205 -    ..
1206 - Summary/Objective
1207 -
120701 - Follow up ref SDS 2 0000.
120702 -
120703 - Completed initial work on modifying SDS batch ops to apply ideas Gary
120704 - submitted a few days ago. ref SDS 0 WM6J  Implementation is explained
120705 - below. ref SDS 0 OS71  This reduces the time required to conform
120706 - a system running Windows 98 to apply the SDS application of the
120707 - Windows Start command for memory management.
120708 -
120709 -
120710 -
120712 -  ..
1208 -
1209 -
1210 - Problem
1211 -
121101 - On 030902 expanded use of Windows Start command.
121102 -
121103 - This entails increasing the number of batch files that support SDS
121104 - functions.  These batch files have two sets of commands for running
121105 - the application under Windows 98 and for Windows 2000.
121107 -  ..
121108 - Gary is still using W98 on his home computer.  On 031016 he submitted
121109 - the following letter...
121110 -
121111 -    1.  Subject: Using the SET command
121112 -        Date: Thu, 16 Oct 2003 07:54:46 -0700
121113 -        From: "EXT-Johnson, Garold L"
121114 -        To: "Rod Welch (E-mail)"
121116 -         ..
121117 -    2.  Rod,
121118 -
121119 -        Batch files recognize a 'SET' command that assigns values to
121120 -        environment variables.
121122 -         ..
121123 -    3.  You already know about using '%' followed by a name to expand
121124 -        an environment variable, as in %systemroot.
121126 -         ..
121127 -    4.  If we add the following lines to SDS.bat before launching SDS:
121128 -
121129 -           set SDS_CMD=%systemroot%\system32\cmd.exe
121130 -           rem set SDS_CMD=C:\WINDOWS\COMMAND.COM
121132 -         ..
121133 -        and then look at the variable in a DOS session, we get:
121134 -
121135 -           SDS_CMD=C:\WINNT\system32\cmd.exe
121137 -         ..
121138 -        demonstrating that environment variables are expanded in 'SET'.
121140 -         ..
121141 -    5.  Now we need only use %SDS_CMD wherever we need to launch a DOS
121142 -        session or START command, and the modification needs to be made
121143 -        in only 1 place.
121145 -         ..
121146 -    6.  By setting temporary variables in a batch file, we can let DOS
121147 -        do the replacing for us.
121149 -         ..
121150 -    7.  03501.bat has a line:
121151 -
121152 -           %systemroot%\system32\cmd.exe /C start /b /wait c:\sd\01\e c:\sd\td\IFHPP
121153 -           c:\sd\03\03501
121155 -         ..
121156 -        where the IFHPP variable needs to be substituted. We could do:
121157 -
121158 -           set SDS_FILE=IFHPP
121159 -        ...
121160 -        %SDS_CMD  /C start /b /wait c:\sd\01\e c:\sd\td\%SDS_FILE c:\sd\03\03501
121162 -         ..
121163 -    8.  Now there is only 1 line to change (the SET command), and it
121164 -        can be in a fixed position.
121166 -         ..
121167 -    9.  This helps in backup.bat where the same directory has to be
121168 -        inserted in several places.
121170 -         ..
121171 -   10.  Using the technique could simplify some of the macros that edit
121172 -        batch files, and effectively eliminate the batch file changes
121173 -        needed to change flavors of windows.
121175 -         ..
121176 -   11.  Thanks,
121178 -         ..
121179 -   12.  Gary
121180 -        x 6-2106
121182 -  ..
121183 - DOS Help explains "set" as follows...
121184 -
121185 -
121186 -    1.  Displays, sets, or removes cmd.exe environment variables.
121187 -
121188 -    2.  SET [variable=[string]]
121190 -           ..
121191 -          variable  Specifies the environment-variable name.
121192 -          string    Specifies a series of characters to assign to the variable.
121194 -         ..
121195 -    3.  Type SET without parameters to display the current environment variables.
121197 -         ..
121198 -    4.  If Command Extensions are enabled SET changes as follows:
121200 -         ..
121201 -    5.  SET command invoked with just a variable name, no equal sign or
121202 -        value will display the value of all variables whose prefix
121203 -        matches the name given to the SET command.  For example:
121204 -
121205 -            SET P
121207 -         ..
121208 -        would display all variables that begin with the letter 'P'
121210 -         ..
121211 -    6.  SET command will set the ERRORLEVEL to 1 if the variable name
121212 -        is not found in the current environment.
121214 -         ..
121215 -    7.  SET command will not allow an equal sign to be part of the name
121216 -        of a variable.
121218 -         ..
121219 -    8.  Two new switches have been added to the SET command:
121220 -
121221 -            SET /A expression
121222 -            SET /P variable=[promptString]
121224 -         ..
121225 -        The /A switch specifies that the string to the right of the
121226 -        equal sign is a numerical expression that is evaluated.  The
121227 -        expression evaluator is pretty simple and supports the
121228 -        following operations, in decreasing order of precedence:
121229 -
121230 -            ()                  - grouping
121231 -            * / %               - arithmetic operators
121232 -            + -                 - arithmetic operators
121233 -            << >>               - logical shift
121234 -            &                   - bitwise and
121235 -            ^                   - bitwise exclusive or
121236 -            |                   - bitwise or
121237 -            = *= /= %= += -=    - assignment
121238 -              &= ^= |= <<= >>=
121239 -            ,                   - expression separator
121241 -         ..
121242 -    9.  If you use any of the logical or modulus operators, you will
121243 -        need to enclose the expression string in quotes.  Any
121244 -        non-numeric strings in the expression are treated as
121245 -        environment variable names whose values are converted to
121246 -        numbers before using them.  If an environment variable name is
121247 -        specified but is not defined in the current environment, then a
121248 -        value of zero is used.  This allows you to do arithmetic with
121249 -        environment variable values without having to type all those %
121250 -        signs to get their values.  If SET /A is executed from the
121251 -        command line outside of a command script, then it displays the
121252 -        final value of the expression.  The assignment operator
121253 -        requires an environment variable name to the left of the
121254 -        assignment operator.  Numeric values are decimal numbers,
121255 -        unless prefixed by 0x for hexadecimal numbers, and 0 for octal
121256 -        numbers. So 0x12 is the same as 18 is the same as 022.  Please
121257 -        note that the octal notation can be confusing: 08 and 09 are
121258 -        not valid numbers because 8 and 9 are not valid octal digits.
121260 -         ..
121261 -   10.  The /P switch allows you to set the value of a variable to a
121262 -        line of input entered by the user.  Displays the specified
121263 -        promptString before reading the line of input.  The
121264 -        promptString can be empty.
121266 -         ..
121267 -   11.  Environment variable substitution has been enhanced as follows:
121268 -
121269 -            %PATH:str1=str2%
121271 -         ..
121272 -        would expand the PATH environment variable, substituting each
121273 -        occurrence of "str1" in the expanded result with "str2".
121274 -        "str2" can be the empty string to effectively delete all
121275 -        occurrences of "str1" from the expanded output.  "str1" can
121276 -        begin with an asterisk, in which case it will match everything
121277 -        from the begining of the expanded output to the first
121278 -        occurrence of the remaining portion of str1.
121280 -         ..
121281 -   12.  May also specify substrings for an expansion.
121282 -
121283 -            %PATH:~10,5%
121285 -         ..
121286 -        would expand the PATH environment variable, and then use only
121287 -        the 5 characters that begin at the 11th (offset 10) character
121288 -        of the expanded result.  If the length is not specified, then
121289 -        it defaults to the remainder of the variable value.  If either
121290 -        number (offset or length) is negative, then the number used is
121291 -        the length of the environment variable value added to the
121292 -        offset or length specified.
121293 -
121294 -            %PATH:~-10%
121295 -
121296 -     .  would extract the last 10 characters of the PATH variable.
121297 -
121298 -            %PATH:~0,-2%
121300 -         ..
121301 -        would extract all but the last 2 characters of the PATH
121302 -        variable.
121304 -         ..
121305 -   13.  Finally, support for delayed environment variable expansion has
121306 -        been added.  This support is always disabled by default, but
121307 -        may be enabled/disabled via the /V command line switch to
121308 -        CMD.EXE.  See CMD /?
121310 -         ..
121311 -   14.  Delayed environment variable expansion is useful for getting
121312 -        around the limitations of the current expansion which happens
121313 -        when a line of text is read, not when it is executed.  The
121314 -        following example demonstrates the problem with immediate
121315 -        variable expansion:
121316 -
121317 -            set VAR=before
121318 -            if "%VAR%" == "before" (
121319 -                set VAR=after;
121320 -                if "%VAR%" == "after" @echo If you see this, it worked
121321 -            )
121323 -         ..
121324 -        would never display the message, since the %VAR% in BOTH IF statements
121325 -        is substituted when the first IF statement is read, since it logically
121326 -        includes the body of the IF, which is a compound statement.  So the
121327 -        IF inside the compound statement is really comparing "before" with
121328 -        "after" which will never be equal.  Similarly, the following example
121329 -        will not work as expected:
121330 -
121331 -            set LIST=
121332 -            for %i in (*) do set LIST=%LIST% %i
121333 -            echo %LIST%
121335 -         ..
121336 -        in that it will NOT build up a list of files in the current directory,
121337 -        but instead will just set the LIST variable to the last file found.
121338 -        Again, this is because the %LIST% is expanded just once when the
121339 -        FOR statement is read, and at that time the LIST variable is empty.
121340 -        So the actual FOR loop we are executing is:
121341 -
121342 -            for %i in (*) do set LIST= %i
121344 -         ..
121345 -        which just keeps setting LIST to the last file found.
121347 -         ..
121348 -   15.  Delayed environment variable expansion allows you to use a
121349 -        different character (the exclamation mark) to expand
121350 -        environment variables at execution time.  If delayed variable
121351 -        expansion is enabled, the above examples could be written as
121352 -        follows to work as intended:
121353 -
121354 -            set VAR=before
121355 -            if "%VAR%" == "before" (
121356 -                set VAR=after
121357 -                if "!VAR!" == "after" @echo If you see this, it worked
121358 -            )
121360 -             ..
121361 -            set LIST=
121362 -            for %i in (*) do set LIST=!LIST! %i
121363 -            echo %LIST%
121365 -         ..
121366 -   16.  If Command Extensions are enabled, then there are several
121367 -        dynamic environment variables that can be expanded but which
121368 -        don't show up in the list of variables displayed by SET.  These
121369 -        variable values are computed dynamically each time the value of
121370 -        the variable is expanded. If the user explicitly defines a
121371 -        variable with one of these names, then that definition will
121372 -        override the dynamic one described below:
121373 -
121374 -        %CD% - expands to the current directory string.
121376 -         ..
121377 -        %DATE% - expands to current date using same format as DATE
121378 -        command.
121380 -         ..
121381 -        %TIME% - expands to current time using same format as TIME
121382 -        command.
121384 -         ..
121385 -        %RANDOM% - expands to a random decimal number between 0 and
121386 -        32767.
121387 -
121388 -        %ERRORLEVEL% - expands to the current ERRORLEVEL value
121390 -         ..
121391 -        %CMDEXTVERSION% - expands to the current Command Processor
121392 -        Extensions version number.
121394 -         ..
121395 -        %CMDCMDLINE% - expands to the original command line that
121396 -        invoked the Command Processor.
121397 -
121398 -
121399 -
121400 -
1215 -

SUBJECTS
SDS.BAT DOS Environment Variables Set Command for Windows Start Comm
DOS Environment Variables Windows 2000 Windows 98 SDS Batch Files an

1504 -
150501 -  ..
150502 - SDS System Launch Batch Files Modified to Apply Windows Set Command
150503 -
150504 - To implement Windows "set" command for environment variables, per
150505 - above, ref SDS 0 M44N, and following up initial work using environment
150506 - variables on 030504, ref SDS 1 CM7M, the record today led to trying
150507 - following....
150508 -
150509 -              [On 040422 ran these systems on Windows XP computer
150510 -              successfully. ref SDS 6 6I4L
150511 -
150512 -        1.  For...
150514 -                      ..
150515 -                     c: sd 01 dos.bat........... ref OF 11 BH4M
150516 -                     c: sd 01 sds.bat........... ref OF 13 UH4N
150517 -                     c: sd 01 mj.bat............ ref OF 12 GB4M
150519 -             ..
150520 -            Created set commands....
150521 -
150522 -                 rem        Windows 2000 command environment
150523 -                 rem
150524 -                 rem           Applied in batch ops for using Windows
150525 -                 rem           Start command
150526 -                 rem
150527 -                 rem
150528 -                 set SDS_CMD=%systemroot%\system32\cmd.exe
150529 -                 set SDS_C32=%systemroot%\system32
150530 -                 set SDS_STRT=/b /wait
150531 -                 rem
150532 -                 rem        Windows 98 command environment
150533 -                 rem
150534 -             **  rem set SDS_CMD=C:\WINDOWS\COMMAND.COM
150535 -             **  rem set SDS_C32=C:\WINDOWS
150536 -             **  rem set SDS_STRT=/min /wait
150537 -                 rem
150538 -                 rem
150539 -                 rem
150541 -             ..
150542 -        2.  The only file that likely has to be changed for Gary's home
150543 -            computer is sds.bat.  The dos.bat file could be used to
150544 -            launch SDS apps, which then require the correct settings,
150545 -            as in sds.bat.  However, SDS is normally only launched from
150546 -            a DOS prompt after doing compiler ops for testing, and
150547 -            typically Gary is not working in this area.
150549 -               ..
150550 -              [On 031028 applied to c: sd 01 backup.bat for maintaining
150551 -              temproary transfer directory. ref SDS 4 N47I
150553 -               ..
150554 -              [On 031020 expanded use of environment variables in
150555 -              00903.bat, ref SDS 3 TC6G, and in the SDS program launch
150556 -              op sds.bat to enable using the Windows Start command to
150557 -              open files with other applications. ref SDS 3 NW3N
150559 -               ..
150560 -              [On 031121 modified batch files by shortening length of
150561 -              set commands to avoid overrunning something in DOS.
150562 -              ref SDS 5 XA6O
150563 -
150564 -              [On 040422 ran these systems on Windows XP computer
150565 -              successfully. ref SDS 6 6I4L
150567 -             ..
150568 -            As a result, when SDS is updated, Gary has only one file to
150569 -            change for his home computer...
150570 -
150571 -                               c: sd 01 sds.bat
150572 -
150573 -
150574 -
150576 -  ..
150577 - Subject Index Modify 035012 for Constructing Transfer Filename
150578 - 035012  Load Transfer File for Subject Index Start Command Batch File
150579 -
150580 - Line 110, ref OF 2 IQ5F, in 035012
150581 -
150582 -    e c:\sd\01\03501.bat
150583 -      z 24 38
150584 -    z 8 69
150585 -    l !/C start!
150586 -    loc_cur 3 20
150587 -      z 56 69
150588 -    fr !sd\td\!
150589 -
150590 -        Modified zone and eliminated a command for distinguishing
150591 -        between configuring sds.bat for w2k and for w98.  As a result
150592 -        of developing set command for environment variable, per above,
150593 -        there is now only a single command in the 03501.bat file where
150594 -        the transfer file needs to be constructed.
150595 -
150596 -
150597 -
150598 -
150599 -
1506 -