The mi_system() function

The mi_system() function allows you to execute operating system commands from within a DataBlade® module or C UDR.

Syntax

mi_integer mi_system(const mi_char *cmd);
cmd
An operating system command, surrounded by quotation marks.
Valid in client LIBMI application? Valid in user-defined routine?
Yes Yes

Usage

Use the mi_system() function from within a DataBlade module or C UDR to execute operating system commands, external user executables, or shell scripts. The mi_system() function creates a child process to execute the command, waits for its completion, and then returns the command’s exit status to the calling routine. The child process inherits the user and group IDs of the client running the session.

The mi_system() function does not perform any validation on the command you run, therefore, you must take care to run appropriate and accurate commands. For information about good coding practices within user-defined routines, see the HCL OneDB™ DataBlade API Programmer's Guide.

The following code snippet shows how to use the mi_system() function to execute the rm /tmp/lo* command:
ret = mi_system(“rm /tmp/lo*”); 
check_retval(ret); /* Check exit status */ 
To use the mi_system() function on Windows™ computers, specify the name and absolute path name of the user executable or file to use within the mi_system() call. For example:
 mi_system("/p1/p2/myexe param1 param2")
or
mi_system("sh /p1/p2/myscript.sh")

The mi_system() function treats the first string within the quotation marks as the command and the following strings as parameters passed to the command.

To run a command that includes symbols interpreted by the shell, put them inside a shell script and run the shell script through mi_system(). For example, this command does not work:
mi_system("echo 'Check this out' >> /tmp/myfile")
because mi_system() treats echo as the command to be run and 'Check this out', >>, and /tmp/myfile as its parameters. To successfully run these commands, create a shell script, such as mysh.sh, which contains the following lines:
#!/bin/sh
echo 'Check this out' >> /tmp/myfile
Next, run the following command:
mi_system("sh /p1/p2/mysh.sh")

For more information about executing operating system commands, see the HCL OneDB DataBlade API Programmer's Guide.

Return values

An integer
The success, failure, or error code returned by the operating system command.
MI_ERROR
The operating system command cannot be executed.