OS/2 Batch File Commands

The Batch File Commands are listed here alphabetically, you may browse through them or you may click on the links below.


  • CALL
  • ECHO
  • ENDLOCAL
  • EXTPROC
  • FOR
  • GOTO
  • IF
  • PAUSE
  • REM
  • SETLOCAL
  • SHIFT

  • CALL
    Calls a batch file from within another batch file without ending the first one. A batch file can then be used as commands from within a master batch file.

    CALL ---------- batchfile-------------|------------|-----| |- argument -| Related Commands: Echo EndLocal ExtProc For GoTo If Pause Rem SetLocal Shift

    It is important to note that:

    As an example, assume that you have two batch files. Your first batch file is named EXAMPLE1.CMD, which contains these commands:

    ECHO EXAMPLE1.CMD is running ... CALL EXAMPLE2 ECHO EXAMPLE1.CMD is running again ... Your second batch file, the one you want to call, is EXAMPLE2.CMD. It contains: ECHO EXAMPLE2.CMD is running now ... If you are in the root directory when you type EXAMPLE1 at the OS/2 command prompt, the following is displayed on your screen: [C:\] ECHO EXAMPLE1.CMD is running ... EXAMPLE1.CMD is running ... [C:\] ECHO EXAMPLE2.CMD is running now ... EXAMPLE2.CMD is running now ... [C:\] ECHO EXAMPLE1.CMD is running again ... EXAMPLE1.CMD is running again ...
    ECHO
    Allows or prevents the screen display of OS/2 commands as they are run from a batch file. ECHO does not interfere with messages produced while commands are running.

    ECHO -----------------|----------------|-------------------| |------ ON -----| |------ OFF -----| |---- message ---| Related Commands: Pause Rem

    Enter this command without a parameter to display the current ECHO state.

    You can control (|) and redirect (>) output from a batch file.

    To prevent DOS from interpreting the | and > symbols, enclose them in double quotes. ECHO OFF ECHO PIPING "|" ECHO REDIRECTION ">" To prevent the OS/2 operating system from interpreting the | and > symbols, precede them with a ^ symbol. The ^ symbol tells the system to interpret the next character input, but not to display it. ECHO OFF ECHO PIPING ^| ECHO REDIRECTION ^> You can also control how batch-file lines or command lines are displayed. To prevent the system from displaying a batch-file line, place an @ before the command. @ECHO ON @REM THIS LINE IS NOT DISPLAYED REM THIS LINE IS DISPLAYED @FILE1 To display lines of text in a batch file, but prevent the display of command lines, follow this example: @ECHO OFF REM THIS LINE WILL NOT BE DISPLAYED ECHO THIS LINE WILL BE DISPLAYED In the following example, the system first displays ECHO OFF but does not display the REM or first DIR C:\OS2\SAMPLE.ABC commands because ECHO is OFF. However, the system still displays the output of the DIR command. Next, ECHO ON is processed and the system displays the DIR C:\OS2\SAMPLE.ABC command with the DIR output. ECHO OFF REM **** COMMAND DISPLAY IS NOW OFF DIR C:\OS2\SAMPLE.ABC ECHO ON DIR C:\OS2\SAMPLE.ABC When the above batch file is run, the following is displayed: ECHO OFF The volume label in drive C is OS2. Directory of C:\ SAMPLE.ABC 1234 7-17-88 12:14p 1 File(s) 141312 bytes free DIR C:\OS2\SAMPLE.ABC The volume label in drive C is OS2. Directory of C:\ SAMPLE.ABC 1234 7-17-88 12:14p 1 Files(s) 141312 bytes free
    ENDLOCAL
    Restores the drive, directory, and environment variables that were in effect before the SETLOCAL command was processed.

    ENDLOCAL --------------------------------------------------| Related Commands: SetLocal

    This command ends the SETLOCAL command, restoring the previous drive, directory, and environment settings. You can issue an ENDLOCAL command even if no SETLOCAL command is running.

    If you want to insert the ENDLOCAL command within a batch file to restore the drive, directory, and environmental variables, follow this example: PATH SETLOCAL A: CD \XYZ PATH A:\;A:\MISCPGM PATH ENDLOCAL PATH Note that the PATH command with no parameters displays the current value for PATH. You can see that the original current drive, directory, and environment value for PATH are saved when SETLOCAL is issued, and restored when ENDLOCAL is issued.


    EXTPROC
    Defines an external batch processor for a batch file.

    EXTPROC |---------|-|--------|- filename -|-------------|--| |- drive -| |- path -| |- arguments -| This command is useful if you have your own batch processor and want to substitute it for the OS/2 batch processor.

    You must include the EXTPROC command as the first statement in any batch file you want processed by your batch processor. CMD.EXE calls your batch processor to process your batch-file statements.

    For example, if you wanted to use a batch processor called MYBATCH.EXE, located in the C:\BATCH directory, to run some of your batch files, type the following in your batch file: EXTPROC C:\BATCH\MYBATCH.EXE
    FOR
    Allows repetitive running of OS/2 commands.

    To use FOR from the OS/2 command prompt: FOR --- % variable --- IN --- (set) --- DO ---- command ---| To use FOR from a batch file: FOR ------ %%c ------- IN ---- (set) ---- DO ---- command -| It is important to note that:

    In the following example, FOR sequentially sets the %%D parameter to each item in the set and then evaluates the command you want to run (TYPE).

    Assume you want a batch file to process the commands, TYPE FILE1 and TYPE FILE2, and have the result be the same as if you typed both commands from the command prompt: FOR %%D IN (FILE1 FILE2) DO TYPE %%D Assume you want to process the commands TYPE FILE1 and TYPE FILE2 from the command prompt: FOR %H IN (FILE1 FILE2) DO TYPE %H
    GOTO
    Transfers control to the line that follows the one containing the appropriate label.

    GOTO --------------------- label -------------------------| Related Commands: If

    It is important to note that:


    IF
    Allows conditional processing of OS/2 commands. When the condition is true, the operating system processes the command; otherwise, it skips the command and processes the next command in the file.

    Piping and redirection should not be specified on the IF command line.

    IF --|-------|--|- ERRORLEVEL --- number -----------|------ |- NOT -| |- string1==string2 ----------------| . . . . . . ----|-----------------------------------------------|----- |- EXIST --|---------|--|--------|-- filename --| |- drive -| |- path -| . . . . . .----------- command ------------------------------------| For readability, the file name parameters are shown on a separate line in this diagram. When you type the IF command, you can specify either an error level, string, or a file name.

    Related Commands: GoTo


    PAUSE
    Suspends processing of the batch file and displays the following message: Press any key when ready . . . PAUSE ------------|-----------|----------------------------| |- comment -| Related Commands: Echo Rem<

    Enter this command to display the message: Press any key when ready.... You can control how much of a batch file you want to process by placing PAUSE commands at strategic points in the file. At each PAUSE statement, the system stops and gives you time to decide whether to stop the processing. Press and hold Ctrl+Break, and type Y to stop a batch file from processing. In a DOS session, press any key to continue processing. In an OS/2 session, you cannot continue processing.


    REM
    Adds comments or line spacing in a batch file or a CONFIG.SYS file.

    REM --------------|-----------|----------------------------| |- comment -| When adding remarks or line spacing in a batch file, it is important to note that:

    You can use the REM command to add remarks or line spacing to your CONFIG.SYS file. Any lines of text added using REM are ignored by the system during CONFIG.SYS processing and are not displayed on your display terminal.


    SETLOCAL
    Lets you define the drive, directory, and environment variables that are local to the current batch file.

    SETLOCAL --------------------------------------------------| Related Commands: EndLocal<

    This command saves the current drive, directory, and environment variables and lets you define local variables for the batch file. The previous drive, directory, and environment settings are restored when the ENDLOCAL command is encountered, or when the batch file ends.

    If a matching ENDLOCAL command is not found, the saved elements are restored when the processing of the batch file that issued the SETLOCAL command ends. In this way, any environment variable and the current drive and directory can be altered without affecting the command processor. Issuing multiple SETLOCAL commands without matching ENDLOCAL commands is not considered an error.


    SHIFT
    Allows command lines to use more than 10 replaceable parameters in batch file processing.

    SHIFT -----------------------------------------------------| It is important to note that:

    As an example, assume: A SHIFT results in the following: %0 = 'A' %0 = 'B' %1 = 'B' %1 = 'C' %2 = 'C' %2 - %9 are empty %3 - %9 are empty


    If you experience a problem with this page, please send a message to JTate@JaTomes.Com including a description of the problem.

    Last modified: Thursday Aug-06-1998.