Share this page

# system

Process Control Functions

Executes an operating system command.

    int system( const char *string);

string | The string that is passed to the resident operating system for execution.

## Return Values

If a command was successfully executed the command interpreter returns an adequate value; generally 0 indicates that the action performed by the command interpreter terminated with no errors.

A return value of -1 indicates an error, and global variable errno is set to one of the following errors:

Value | Description
ENOENT | Command interpreter not found
ENOEXEC | Command interpreter is not executable
ENOMEM | Error allocating memory for the process
E2BIG | Argument list too big

For system details, refer to your C language documentation.

## Example

This example, for the Windows platform, creates a new directory, xyz, and a new file under it, short_lifespan.txt.

The system function executes a dir command. The output of the command is written (using `>') to the newly created file. The content of the file should be a list of the contents of the C drive.

        char filename[1024], command[1024];
        char new_dir[] = "C:\\xyz";

        // Create a directory under root called xyz and make it the current dir

        if (mkdir(new_dir))
            lr_output_message ("Create directory %s failed", new_dir);
        else
            lr_output_message ("Created new directory %s", new_dir);

        sprintf(filename, "%s\\%s", new_dir, "newfile.txt");

        // Execute a dir /b command and direct it to a new file

        sprintf(command, "dir /b c:\\ > %s /w", filename);
        system(command);
        lr_output_message ("Created new file %s", filename);

    Example: output:
    Action.c(10): Created new directory C:\xyz
    Action.c(17): Created new file C:\xyz\newfile.txt

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: