Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : OS-COMMAND statement
 

OS-COMMAND statement

Escapes to the current operating system and executes an operating system command.

Syntax

OS-COMMAND
[ SILENT | NO-WAIT | NO-CONSOLE ]
[ command-token | VALUE ( expression ) ]...
SILENT
After processing an operating system command, the AVM shell pauses. To exit the window in Windows GUI platforms, you must type exit. To exit the window in Windows character platforms, you must type exit and press RETURN or SPACEBAR. You can use the SILENT option to eliminate this pause. Use this option only if you are sure that the program, command, or batch file does not generate any output to the screen. Cannot be used with NO-WAIT.
NO-WAIT
In a multi-tasking environment, causes the AVM to immediately pass control back to next statement after the OS-COMMAND without waiting for the operating system command to terminate. Cannot be used with SILENT. This option is supported in Windows only.
NO-CONSOLE
While processing an operating system command, the AVM creates a console window. The console window may not be cleaned up after the command is executed. You can use the NO-CONSOLE option to prevent this window from being created in the first place.
command-token | VALUE ( expression )
One or more command words and symbols that you want to pass the operating system to execute. The VALUE option generates the command tokens included in expression, a character string expression. The specified combination of command-token and VALUE(expression) options can form any legal combination of commands and command options permitted by the operating system. These can contain Unicode characters. See OpenEdge Development: Internationalizing Applications for more information about Unicode.

Example

There are two principal uses for the OS-COMMAND statement: to execute a utility that has the same syntax on two or more different operating systems, and to execute an operating system statement input by a user.
In both instances, the OS-COMMAND statement eliminates the need to use the OPSYS statement to determine the operating system and then use conditional logic to execute the appropriate code. The OS-COMMAND statement, therefore, makes an application more portable.
This procedure prompts the user for an operating system command and then uses the OS-COMMAND statement to execute the command:
r-os-com.p
DEFINE VARIABLE comm-line AS CHARACTER NO-UNDO FORMAT "x(70)".

REPEAT:
UPDATE comm-line.
OS-COMMAND VALUE(comm-line).
END.

Notes

*If you want to run an operating system internal command, such as Windows dir, do not use the NO-WAIT keyword. The results are unpredictable.
*If you want to run an application that requires Windows, you must use the NO-WAIT option.
*The NO-WAIT option is unavailable in environments that are not multi-tasking.
*The OS-COMMAND statement always sets the value for the OS-ERROR function to 0, whether or not an error occurs. Thus, an operating system error is never returned for the OS-COMMAND statement.

See also

DOS statement, OPSYS function, OS-ERROR function, UNIX statement