Scripting: Batch Script May Misbehave RandomlyIn batch scripting, complex tasks may require storing values in environment variables, and calling other batch files or subroutines. In this situation the various scripts/routines may malfunction. One problem to look for is environment veriable reuse. For example, if a batch file stores values in an environment variable called TMP1 (say), and then calls a subroutine/batch which also stores values in a variable of that name, the original batch will exihibit hard-to-debug behaviour. One remedy for this is to use environment variables named for the routine/script they are in, eg. TMP_GetDate, TMP_FileSize etc [Another reason scripts may behave bizarrely is if the system has an Autorun entry for the command processor listed under either of the following registry keys: HKCU\Software\Microsoft\Command Processor, HKLM\Software\Microsoft\Command Processor. This is because a FOR /F loop actually runs a new instance of CMD.EXE to spawn the command that is being parsed, and this triggers the Autorun command. If the command listed under Autorun outputs to the console, that output will also be included in the original command's console output, which can interfere with the parsing of the desired command.] |