Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    14

    Unanswered: Is it possible to run OS command from stored procedure

    hi,
    We're using DB2 V8.2 (FP10) on 64 bit linux.(SLES 9.0).

    Is there a way to execute an operating system command from a db2 stored procedure?

    Thanks.

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    You can write a C or Java UDF that issue Operating System Commands and call them from your SQL Stored Proc

    HTH

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    BTW,
    http://www-128.ibm.com/developerwork...0302izuha.html
    shows an example of writing to a file.
    You can 'reuse' the code to issue OS commands

    HTH

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  4. #4
    Join Date
    Apr 2005
    Posts
    14
    hi,
    Thanks for the link
    I'm not highly qualified on the development side.
    I wrote a c simple c code which can send operating system commands as
    OS2.c
    #include <stdio.h>
    int main (int argc, char** argv)
    {
    system(argv[1]);
    }
    and compile it with "cc OS2.c -o OS2" command and copied it into sqllib/function directory.

    Then I create an external stored procedure as
    CREATE PROCEDURE OS_COMMAND (IN COMMAND VARCHAR(20)) EXTERNAL NAME 'OS2!main' FENCED LANGUAGE C PARAMETER STYLE GENERAL;
    command.

    When I call the procedure; I'm getting DARI errors.

    db2inst1@DBTEST:~/sqllib/adm> db2 "call OS_COMMAND('ls')"
    SQL1131N DARI (Stored Procedure) process has been terminated abnormally.
    SQLSTATE=38503


    The examples that I find in sqllib/samples/c/spserver.c code are too complicated for me.

    Are there any simple examples for creating external stored procedures?
    Thanks.

  5. #5
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Have a look at the spserver.c example code ... You'll have to follow that format for input parms etc ...

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •