>From Sam Rose
> I've tried this...
> but it doesn't like my source, probably because I need to return this
> value, i.e. hit the enter button after this, is there a bit of code
> that I can achieve this with?
>
>
> String command ="source /opt/bin/coraenv";
> String runsql = "sqlplus";
>
> Runtime runtime = Runtime.getRuntime();
> Process process = null;
> Process sql = null;
>
> try {
>         process = runtime.exec(command);
>         sql = runtime.exec(runsql);
> }//end try
>
> this brings up
>
> java.io.IOException: source: not found

First "source" is a C-shell built-in command.  I suspect that runtime.exec()
is using /bin/sh to interpret the command, as this is (I believe) standard
for the Standard C/POSIX.2 system() command.

Second coraenv is setting up your shell environment for running sqlplus, but
this is lost when the shell exits, ending the first runtime.exec().  The
second runtime.exec() gets a new shell with a pristine environment.  Not
what you want :).

Create a small shell script, mark it as executable, and put it where your
servlet can find it.

FILE /theworkingdirectory/run_sqlplus
----
#!/bin/sh
. /opt/bin/coraenv
/pathtosqlplus/sqlplus
----

Where /theworkingdirectory/ is the current working directory when your
servlet is invoked.

Also /pathtosqlplus/ is the absolute path to where sqlplus is installed.
Might not be necessary, but absolute paths in scripts executed by
priviledged processes is often a good idea for security.

Then your Java looks like:
----
String command = "./run_sqlplus";

try {
        Runtime runtime = Runtime.getRuntime();
        Process sql = runtime.exec(command);
        ...etc
}
----

Of course I can't try this at the moment, so I probably got *something*
wrong... :).

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to