Velocity Scheduler

2.5 Miscellaneous Script Tips

All batch jobs should read and write to local disk (T:) instead of using the remote fileserver (H:), always!

Reading and writing files locally is faster and safer than doing I/O over the network. In addition to significant speedups, it can mean the difference between a job that works and one that fails, either because the job ran out of time or a network hiccup occurred while a file being accessed over the network was open at the time of the interruption.  More information . . .

Running script files from within a batch script

When you execute a .bat file from another .bat file, it runs the new one and never returns control to the original, unless you use the "call" command. For example, to include sleep.bat in your batch script, use the command

When executing a .bat file from another .bat file, use "call" to return control to the original, e.g.,

call sleep.bat 60

This sometimes shows up as a mysterious batch script problem; it appears that the script simply "stalls", particularly when one includes a command with no suffix.

Changing drives

To change your current working directory on a single drive, use the cd command:

H:\users\userid> cd temp
H:\users\userid\temp>

To change your current working directory to a location on another drive, either use two steps:

H:\users\userid\temp> T:
T:\> cd userid
T:\userid>

or use the /D option of cd:

H:\users\userid\temp> cd /D T:userid

However, you should be aware that when you change drives by just entering the drive name, e.g. T: you will go to the current working directory on T:, not the top level. For example:

H:\users\userid\temp> T:
T:\userid> copy H:data.txt

Note: Whenever a drive letter is specified without a trailing \, such as H:, it refers to the current working directory on that drive. Therefore, the last line will copy H:\users\userid\temp\data.txt to T:\userid\data.txt

Copying files

When copying files between the file server and your batch node, be aware that copy only takes two arguments, source and destination. Therefore, using a wildcard or directory name to specify source is fine, e.g.

copy T:\userid\data*.txt %ROOTDIR%
copy T:\userid\alloutfiles\ %ROOTDIR%
but using a variable that expands into several will not work, e.g.
set OUTFILES=file1 file2 file3
copy T:\userid\%OUTFILES% %ROOTDIR%

When copying files, remember that copy only takes two arguments, source and destination. You can copy multiple files using a wildcard or directory name, but not a variable which expands into several names.

Popup screen messages

Check both your program and script for the possibility of popup messages sent to the screen. When your batch job is running, all popup messages intended for the screen will go to the batch machine's virtual screen: you won't see it, and no one can check it for you. Also keep in mind that popup error messages will similarly go to a screen you can't see. For example, if you write a program statement that involves division you incur the risk that a window will pop up announcing that you have divided by 0. Or if you put a variable on the left side of an equation, there is always a risk that you will have a segfault. In other words, your program may fail, reporting an error message that you'll never receive. One exception is that you can capture standard error from your program to a file; see example 2 in section 2.3.

Popup messages sent to the screen will go to the batch machine's virtual screen, which no one can see.

Timing

There are currently three options for timing a command in a batch script.

  1. Issue "time /t" before and after the command(s) you wish to time. This command reports wall clock time. Issue "help time" for more information.

  2. You can use "timethis", e.g. "timethis run.exe". (To put "timethis" in your path, make sure you first run H:\CTC Tools\setup_visualc.bat.) The resolution is better, but it's still run time, not cpu time. Obtain more information by entering "timethis /?".

  3. Another option is to use the GNU time command in cygwin, but you have to specify the whole path (or use DOSKEY to set up an alias) in order to bypass the MS-DOS time command. E.g.
    C:\cygwin\bin\time run.exe
    

    For more information, issue

    C:\cygwin\bin\time.exe --help