Progress
Portability Guide


Standard System Commands

Where possible, use standard system commands instead of variants unique to certain hardware manufacturers. Table 4–1 lists the OS statements that promote portability by avoiding limitations of operating-system-specific commands. These statements allow you to create a single version of a procedure that works differently on varying operating systems.

Table 4–1: OS Statements
OS Statement
Description
OS-APPEND
Performs a system call to execute the operating system command that appends two files.
OS-COMMAND
Performs a system call to execute an operating system command that you specify.
OS-COPY
Performs a system call to execute the operating system command that copies a file.
OS-CREATE-DIR
Performs a system call to execute the operating system command that creates a new directory.
OS-DELETE
Performs a system call to execute the operating system command that deletes a file or directory. You can delete one or more files, a directory, or an entire directory branch.
OS-DRIVES
Performs a system call to execute the operating system command that returns a comma-separated list of the available drives in Windows.
OS-ERROR
Returns a Progress error code that indicates whether an execution error occurred during the last OS-APPEND, OS-COMMAND, OS-COPY, OS-CREATE-DIR, OS-DELETE, or OS-RENAME statement.
OS-GETENV
Performs a system call to execute the operating system command that returns a string containing the value of the specified environment variable in the environment in which Progress is running.
OS-RENAME
Performs a system call to execute the operating system command that renames a file or directory.

See the Progress Language Reference for more information on these statements.

OS-COMMAND

Use the OS-COMMAND statement to execute an operating system statement that you cannot execute using the OS statements listed in Table 4–1. The OS-COMMAND statement provides a generic, operating-system-independent way to escape to the current operating system, which lets you:

The arguments to OS-COMMAND must be appropriate for the current operating system. Therefore, where possible, read these arguments at run time from the user, database table, or environment variables rather than hard coding them. The following procedure prompts the user for an operating system command, then uses the OS-COMMAND statement to execute the command:

DEFINE VARIABLE comm-line AS CHARACTER FORMAT "x(70)".
REPEAT:
     UPDATE comm-line.
     OS-COMMAND VALUE(comm-line).
END. 

The OS-COMMAND statement eliminates the need to use the OPSYS function to determine the operating system. However, if you cannot use the OS-COMMAND statement, use the OPSYS function to determine the operating system you are running on, and use conditional logic to execute the appropriate code using one of the operating-system-specific escape statements.

The NO-WAIT option of OS-COMMAND is valid only in multi-tasking environments. This option causes Progress to pass control to the statement following the OS-COMMAND, without waiting for the operating system command to terminate. If you are using the OS-COMMAND statement to run an independent Windows application, use the NO-WAIT option.

For more information, see the OS-COMMAND Statement reference entry in the Progress Language Reference.

INPUT FROM OS-DIR

You generally use the INPUT FROM statement to read the contents of an operating system file; however, you can also read a list of the files in a directory using the OS-DIR option of the INPUT FROM statement. The INPUT FROM statement specifies a new input source. Using INPUT FROM OS-DIR indicates that you want your input to be the filenames found in the directory you specify. If that directory is not a valid directory or you do not have permission to read it, an error condition occurs. Otherwise, Progress generates the directory list and sends it to the calling program through the INPUT stream. An INPUT CLOSE statement discards any unread filenames from the list.

The following example uses the OS-GETENV function to find the path of the DLC directory, then uses the OS-DIR option of INPUT FROM to read the contents of the directory:

DEFINE VARIABLE search-dir AS CHARACTER.
DEFINE VARIABLE file-name AS CHARACTER FORMAT "x(16)" LABEL "File".
DEFINE VARIABLE attr-list AS CHARACTER FORMAT "x(4)" LABEL "Attributes". 
search-dir = OS-GETENV("DLC"). 
INPUT FROM OS-DIR(search-dir). 
REPEAT:
   SET file-name ^ attr-list
          WITH WIDTH 70 USE-TEXT TITLE "Contents of " + search-dir.
END. 
INPUT CLOSE. 

When you use the OS-DIR option, the UNBUFFERED option is ignored. OS-DIR always buffers exactly one filename at a time. When you try to read beyond the last filename in the list, Progress generates the ENDKEY condition.

See the Progress Language Reference for more information on the INPUT FROM statement.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095