Re: running a db2 script using execl

From: Arti Potnis (artpot78_at_yahoo.com)
Date: 06/26/04


Date: 26 Jun 2004 01:14:32 -0700


"Gary R. Hook" <nospam@nospammers.net> wrote in message news:<N9ZCc.8755$BD4.7144@newssvr24.news.prodigy.com>...
> 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.



Relevant Pages

  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)
  • Why newbies dont RTFM...
    ... Even though I've used Linux before, I've never had to do any ... BASH BUILTIN COMMANDS ... last command exited within ... unless the shell is not exeâ ...
    (comp.os.linux.misc)
  • Re: Great SWT Program
    ... None of the nasty things that you have said or implied about me are at ... treat the file as input (manually invoking the command interpreter ... script, copy the line into that within the editor, exit, and invoke ... the shell script. ...
    (comp.lang.java.programmer)
  • Re: ksh silently ignores function if mistakenly not autoloaded
    ... Here's the order of execution. ... This really takes place prior to command ... Shell scripts, with all their power, have one major drawback - they ... In the Korn Shell, there are two separate syntaxes for defining ...
    (comp.unix.shell)
  • Re: Wait for background processes to complete
    ... trying to use the shell concepts and maximize parallelism). ... the systemcommand - which leaves us back at square one. ... fork, and then do your own wait. ... PID PGID COMMAND ...
    (comp.lang.perl.misc)