Runs an executable via a system shell.
Restriction: This function is supported for native COBOL only.


#include <sys/wait.h>

int SYSTEM (const unsigned char *cmd);


cmd A null-terminated system command line to be executed.


The specified command line is passed to a shell and executed, as for the C library routine system().

As the COBOL environment is unaware of any output from another process, such as the shell or command executed during SYSTEM(), you must ensure that the screen is either not updated during the SYSTEM() call or is redisplayed after execution of the call.

The return value from this routine is the same format as that returned from the C library routine system(). There are macros in the C library include file sys/wait.h to manipulate this value and get the return code of the executed command. See your system documentation for more information.

Equivalent COBOL Syntax:

call "CBL_EXEC_RUN_UNIT" using ...


The code below copies one file to another, redirecting standard output and standard error to an error file (which could be subsequently opened and read to see if any output was generated by running the command) and displays the return code of the command:

int res;

res = SYSTEM("cp f1 f2 > errfile 2>&1");

if (WIFEXITED(res))
    cobprintf("Exit status: %d\n", WEXITSTATUS(res));