If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Is it possible to run OS command from stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-06, 03:03
faar faar is offline
Registered User
 
Join Date: Apr 2005
Posts: 14
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.
Reply With Quote
  #2 (permalink)  
Old 03-22-06, 03:20
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #3 (permalink)  
Old 03-22-06, 03:22
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #4 (permalink)  
Old 03-23-06, 02:20
faar faar is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 03-23-06, 20:11
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On