informix
Informix Guide to SQL: Syntax
SPL Statements

SYSTEM

Use the SYSTEM statement to make an operating-system command run from within an SPL routine.

Syntax

Element Purpose Restrictions Syntax
expression Any expression that is a user-executable operating-system command You cannot specify that the command run in the background. Operating-system dependent
SPL_var An SPL variable that contains a valid operating-system command The SPL variable must be of CHAR, VARCHAR, NCHAR, NVARCHAR, or CHARACTER VARYING data type. Identifier, p. 4-205

Usage

If the supplied expression is not a character expression, expression is converted to a character expression before the operating-system command is made. The complete character expression passes to the operating system and executes as an operating-system command.

The operating-system command that the SYSTEM statement specifies cannot run in the background. The database server waits for the operating system to complete execution of the command before it continues to the next statement in the SPL routine.

Your SPL routine cannot use a value or values that the command returns.

If the operating-system command fails (that is, if the operating system returns a nonzero status for the command), an exception is raised that contains the returned operating-system status as the ISAM error code and an appropriate SQL error code.

In DBA- and owner-privileged SPL routines that contain SYSTEM statements, the operating-system command runs with the permissions of the user who is executing the routine.

Specifying Environment Variables in SYSTEM Statements

When the operating-system command that SYSTEM specifies is executed, no guarantee exists that the environment variables that the user application set are passed to the operating system. To ensure that the environment variables that the application set are carried forward to the operating system, enter a SYSTEM command that sets the environment variables before you enter the SYSTEM command that causes the operating-system command to execute.

For information on the operating-system commands that set environment variables, see the Informix Guide to SQL: Reference.

Examples of the SYSTEM Statement on UNIX

The following example shows a SYSTEM statement in an SPL routine. The SYSTEM statement in this example causes the UNIX operating system to send a mail message to the system administrator.

You can use a double-pipe symbol (||) to concatenate expressions with a SYSTEM statement, as the following example shows:

Example of the SYSTEM Statement on Windows NT

The following example shows a SYSTEM statement in an SPL routine. The first SYSTEM statement in this routine causes the Windows NT operating system to send an error message to a temporary file and to put the message in a system log that is sorted alphabetically. The second SYSTEM statement causes the operating system to delete the temporary file.

The expressions that follow the SYSTEM statements in this example contain two variables, %tmp% and %SystemRoot%. Both of these variables are defined by the Windows NT operating system.


Informix Guide to SQL: Syntax, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved