The SYSTEM library routine provides a method of executing an operating system command.
CALL "SYSTEM" USING MY-COMMAND-LINE, GIVING EXIT-STATUS
MY-COMMAND-LINE PIC X(n) | Contains the operating system command line to execute. |
EXIT-STATUS Any numeric data item | Returns the called program's exit status. |
The SYSTEM routine takes a parameter, which is submitted to the host operating system as if it were a command typed in from a terminal.
Some operating systems place limits on the length of a command-line string. Under Windows, the limit is 128 bytes. When you issue a SYSTEM call using a variable, make sure that the length of the variable doesn't exceed the operating system's limit.
The user's terminal is set to its default operating state before this command is run and is reset after it's complete. The runtime system waits for the command to complete.
The status of a call to SYSTEM is placed into EXIT-STATUS. This is usually the exit status of the executed program, or is -1 if the SYSTEM routine failed.
Here's an example of a call to SYSTEM. On a UNIX machine, you could display a directory listing of the /usr directory with the following command:
CALL "SYSTEM" USING "ls /usr"
If your machine is running Windows and you want to execute MS-DOS operating system commands via SYSTEM, you must pass the name COMMAND.COM, as well as the operating system command. Use the syntax shown in this example that executes the DIR command:
CALL "SYSTEM" USING "COMMAND.COM /C DIR"
When CALL "SYSTEM" is used to initiate a program, it looks only for files with a .EXE extension. If you want to call a .COM or .BAT file, you must explicitly add that extension in your code. For example:
CALL "SYSTEM" USING "COMMAND.COM /C MYBATCH.BAT"
The SYSTEM routine is provided in source form as a sample of a C subroutine.
If the command to be executed will not perform any screen I/O, then you can request the SYSTEM routine to retain ACUCOBOL-GT's memory of the user's screen. This will avoid the problem mentioned in the preceding paragraph. To do this, simply pass a second argument to the SYSTEM routine. This may be any parameter you choose. For clarity, we suggest that the second argument be the literal "NO IO".