Unix Technical Forum

running a db2 script using execl

This is a discussion on running a db2 script using execl within the AIX Operating System forums, part of the Unix Operating Systems category; --> Hi, I have a C program in which I use the fork a sub shell. I want to run ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 03:39 AM
Arti Potnis
 
Posts: n/a
Default running a db2 script using execl

Hi,

I have a C program in which I use the fork a sub shell. I want to run
a db2 script in the subshell.
my program is as follows:

lpid=fork();
if(lpid==0) /*child shell*/
{

execl("home/sqllib/db2","db2","-f","myscript.sql",NULL);

}

This doesn't work.However if I use a system command i.e. system("db2
-f myscript.sql"),it seems to work.
I'm new to using aix and am not sure if using a system command would
run this script in the child shell. Do I necessarily have to use execl
for this.If yes, then how ?


thanks in advance
Arti
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 03:39 AM
Gary R. Hook
 
Posts: n/a
Default Re: running a db2 script using execl

Arti Potnis wrote:
> I have a C program in which I use the fork a sub shell. I want to run
> a db2 script in the subshell.
> my program is as follows:
>
> lpid=fork();
> if(lpid==0) /*child shell*/
> {
> execl("home/sqllib/db2","db2","-f","myscript.sql",NULL);
> }
>
> This doesn't work.


Define "doesn't work". We presume it's really "/home/sqllib..." or
whatever the path really is. FWIW relative paths are evil...

> However if I use a system command i.e. system("db2
> -f myscript.sql"),it seems to work.


Perhaps it's an environment issue. I.e. certain variables set up
in the shell but not exported so they don't automatically get
inherited by children. Just a guess. Try your test with the "/bin/env"
command to see if you get different output.

> I'm new to using aix and am not sure if using a system command would
> run this script in the child shell. Do I necessarily have to use execl
> for this.If yes, then how ?


The system() function creates a child shell that looks just like
you typed "ksh" on the command line. It is a child process that
runs and exits when the specified command is complete. You don't
need to use execl(), since it requires you to call fork(), etc.
The system() function does all of that for you. But it provides
less control over file descriptors, and thus has its drawbacks.

--
Gary R. Hook / AIX PartnerWorld for Developers / These opinions are MINE
__________________________________________________ ______________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 03:39 AM
Arti Potnis
 
Posts: n/a
Default Re: running a db2 script using execl

"Gary R. Hook" <nospam@nospammers.net> wrote in message news:<N9ZCc.8755$BD4.7144@newssvr24.news.prodigy.c om>...
> Arti Potnis wrote:
> > I have a C program in which I use the fork a sub shell. I want to run
> > a db2 script in the subshell.
> > my program is as follows:
> >
> > lpid=fork();
> > if(lpid==0) /*child shell*/
> > {
> > execl("home/sqllib/db2","db2","-f","myscript.sql",NULL);
> > }
> >
> > This doesn't work.

>
> Define "doesn't work". We presume it's really "/home/sqllib..." or
> whatever the path really is. FWIW relative paths are evil...
>
> > However if I use a system command i.e. system("db2
> > -f myscript.sql"),it seems to work.

>
> Perhaps it's an environment issue. I.e. certain variables set up
> in the shell but not exported so they don't automatically get
> inherited by children. Just a guess. Try your test with the "/bin/env"
> command to see if you get different output.
>
> > I'm new to using aix and am not sure if using a system command would
> > run this script in the child shell. Do I necessarily have to use execl
> > for this.If yes, then how ?

>
> The system() function creates a child shell that looks just like
> you typed "ksh" on the command line. It is a child process that
> runs and exits when the specified command is complete. You don't
> need to use execl(), since it requires you to call fork(), etc.
> The system() function does all of that for you. But it provides
> less control over file descriptors, and thus has its drawbacks.


--------------------------------------------------------------------

1) By "doesn't work" I mean that the operations that the script is
supposed to perform are not done.The script contains the connect to
db2.. and "LOAD" command for db2.

2)I had used the "which" command to get the path for db2.
I tried using /bin/env but that doesn't solve my problem.

3)Till I figure out a way to use execl for this I'm using system
command


thanks for your response
Arti.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 03:40 AM
mark taylor
 
Posts: n/a
Default Re: running a db2 script using execl

> 1) By "doesn't work" I mean that the operations that the script is
> supposed to perform are not done.The script contains the connect to
> db2.. and "LOAD" command for db2.


Where do you do the "db2 connect to database_name" ? you need to
connect and run your load from the same session .. so if you connect
with one command, then run the load with another you connection will
be lost ... better off writing a script to connect and do the load in
one hit, then running that from your prog.. or start looking at the
db2 cli/api's to do this for you ..

You'll probably find some useful stuff here -->
http://www-136.ibm.com/developerworks/db2/

HTH
Mark Taylor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 03:40 AM
Villy Kruse
 
Posts: n/a
Default Re: running a db2 script using execl

On 25 Jun 2004 07:44:11 -0700,
Arti Potnis <artpot78@yahoo.com> wrote:


> Hi,
>
> I have a C program in which I use the fork a sub shell. I want to run
> a db2 script in the subshell.
> my program is as follows:
>
> lpid=fork();
> if(lpid==0) /*child shell*/
> {
>
> execl("home/sqllib/db2","db2","-f","myscript.sql",NULL);
>



Is there a reason you have "home/sqllib/db2" rather than "/home/sqllib/db2"?


Villy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:18 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com