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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 __________________________________________________ ______________________ |
| |||
| "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. |
| |||
| > 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 |
| ||||
| 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 |