OS-COMMAND statement
- Last Updated: April 7, 2026
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
Escapes to the current operating system and executes an operating system command.
Syntax
|
- 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
SILENToption 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 withNO-WAIT. - NO-WAIT
- In a multi-tasking environment, causes the AVM to immediately pass
control back to next statement after the
OS-COMMANDwithout waiting for the operating system command to terminate. Cannot be used withSILENT. - 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-CONSOLEoption 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
VALUEoption generates the command tokens included in expression, a character string expression. The specified combination of command-token andVALUE(expression)options can form any legal combination of commands and command options permitted by the operating system. These can contain Unicode characters. See Internationalize ABL 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
|
Notes
- If you want to run an operating system internal command, such as Windows
dir, do not use theNO-WAITkeyword. The results are unpredictable. - If you want to run an application that requires Windows, you must use
the
NO-WAIToption. - The
NO-WAIToption is unavailable in environments that are not multi-tasking. - The
OS-COMMANDstatement always sets the value for theOS-ERRORfunction to 0, whether or not an error occurs. Thus, an operating system error is never returned for theOS-COMMANDstatement. - For client processes running on UNIX,
OS-COMMANDstarts a separate process. The client keeps track of subprocesses spawned using an in-memory table with a limit of 20 entries. Therefore, only 20 subprocesses can be open concurrently. If this limit is exceeded, you will see an error:
To avoid this error, limit the number of subprocesses running.SYSTEM ERROR: MAXSUBP: too many subprocesses. (357)Note:INPUT THROUGHalso starts a subprocess. ForINPUT THROUGH, you can useINPUT CLOSEto remove the subprocess from the in-memory table. - On Windows only, when running 32-bit OpenEdge on a 64-bit operating system, if you
attempt to use the
OS-COMMANDstatement to run an executable in the %WINDIR%\System32 directory, execution will fail. To remedy this, you can do one of the following:- Put the files you want to access in the %WINDIR%\SysWOW64 directory.
- Put the files you want to access in another directory and ensure that directory is listed in %PATH%.
- Change your code to use %WINDIR%\Sysnative, to force the operating system to point to %WINDIR%\System32. Note that this can cause problems if the application also runs under a 32-bit version of Windows.
See also
DOS statement, OPSYS function, OS-ERROR function, UNIX statement