Search code examples
informix

How to execute a system command inside a informix stored procedure?


I need to execute a os command inside a informix SPL. My informix instance runs on Solaris machine. I tried with following codes. But gives below mentioned error. Please correct me.

  CREATE PROCEDURE log_message (message VARCHAR(70))

    DEFINE os_command VARCHAR(100);

    -- Output message to log file
    LET os_command = 'ls -ltrh /informix/nuwan/' || message || ' >> /informix/nuwan/test/data.log';

    SYSTEM os_command;

  END PROCEDURE;

Then I called the procedure as follows

 CALL log_message('Test message...');

it give below error

668: The system command cannot be executed or it exited with a non-zero status. 2: No such file or directory


Solution

  • Use the SYSTEM statement to issue an operating-system command from within an SPL routine. https://www.ibm.com/support/knowledgecenter/en/SSGU8G_14.1.0/com.ibm.sqls.doc/ids_sqs_1358.htm