Stored procedure question regarding DB2 for AIX (EE/EEE)

Larry Kirkpatrick

Stored procedure question regarding DB2 for AIX (EE/EEE)
I have a stored procedure question for you.

Is there a way to execute a "native" program or command from a stored
procedure that runs against DB2 for AIX (EEE/EE). For example, I have
attempted to issue the UNIX "ls" command from a "C" stored procedure. I
would think that I could accomplish this by inserting the following line of
code:

system("ls > my/dir/goes/here/out.txt");

It looks like this should redirect the output from the "ls" command to the
file out.txt. However, when this is placed into a stored procedure,
nothing happens. To restate my original question: Is there any way of
executing a "native" program or command from within a "C" stored procedure?
I would also accept a Java solution for this same question!

Thanks

Larry Kirkpatrick
Mutual of Omaha



Abhijit Sinha

Re: Stored procedure question regarding DB2 for AIX (EE/EEE)
(in response to Larry Kirkpatrick)
A Java solution you can try.

1. Put the native command you want to execute in a shell script, complete
with exiting with a success or error return code. Assume your script is
created in: /home/userid/scripts/myscript.ksh.

2. Create a Java stored proc, say MYSCHEMA.SYSCMD as below:

import java.io.*;
public class SysCmd
{
public static void syscmd() throws Exception
{
return;
}
public static int executeAndReturnStatus(String command) throws
Exception
{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec (command);
p.waitFor();
return p.exitValue();
}
}

3. Then, from your original Java SP, just execute the above method giving
the script name as parameter. Check for return code.
...
int rc = SysCmd.executeAndReturnStatus("/home/userid/scripts/myscript.ksh");
...

Let me know if this works.

Abhijit



-----Original Message-----
From: [login to unmask email]
[mailto:[login to unmask email]
Sent: Monday, December 23, 2002 3:57 PM
To: [login to unmask email]
Subject: Stored procedure question regarding DB2 for AIX (EE/EEE)


I have a stored procedure question for you.

Is there a way to execute a "native" program or command from a stored
procedure that runs against DB2 for AIX (EEE/EE). For example, I have
attempted to issue the UNIX "ls" command from a "C" stored procedure. I
would think that I could accomplish this by inserting the following line of
code:

system("ls > my/dir/goes/here/out.txt");

It looks like this should redirect the output from the "ls" command to the
file out.txt. However, when this is placed into a stored procedure,
nothing happens. To restate my original question: Is there any way of
executing a "native" program or command from within a "C" stored procedure?
I would also accept a Java solution for this same question!

Thanks

Larry Kirkpatrick
Mutual of Omaha