views:

476

answers:

4

I am running a shell script through a web application. This shell script looks something like

`#! /bin/bash
user=""
pass=""
db_url=""
db_instance=""
sqlplus -s $user/$pass@$db_url/$db_instance @ ./SqlScripts/foo.sql
sqlplus -s $user/$pass@$db_url/$db_instance @ ./SqlScripts/bar.sql
CLASS_PATH="./lib/*"
java -classpath $CLASS_PATH package.Main ./Data/inputfile`

I am using ProcessBuilder to run the script and everything but the last line works fine. Am I creating a problem by calling shell through the jvm then calling the jvm again to run the application?

A: 

The parent JVM and the child JVM should be separate processes, no particular reason why they should interfere.

What error do you get?

is java on your PATH?

OK, adding more questions in response to your comments ...

Which thread is waiting? Presumably the parent?

The child java process, do you have any evidence as to whether is succesfully initalises. My guess woukld be that the child is in some way blocked. If you kill the child does the parent then come back to life?

Suppose it was a simple "hello world" application, would that work?

djna
yes java is on PATH. No error just hangs with the thread never leaving waiting state.
Kyle
A: 

Often, app servers run their servlets in a 'clean room' environment - e.g. they strip away all the variables that would normally be set from the outside for security reasons. Try using a fully qualified path to the java binary, and also try setting a full/absolute path for your CLASS_PATH variable.

feoh
app servers and standalone apps, the problems is that $ENV_VAR is something the shell understand, not the program. Same goes for any other programming language.
OscarRyz
A: 

Most likely the line:

CLASS_PATH="./lib/*"

And

$CLASS_PATH

It won't be expanded by the process builder because that's usually shells' job, which in this situation is not being invoked.

Try creating the complete list of ./lib/* and append it directly into the last line of your script.

java -classpath ./lib/a.jar:./lib/b.jar

Side note:

Invoking all this from java looks just bad to me. I would rather have it in a standalone script and invoke it by other means, but that's me.

OscarRyz
that was just an example... not the actual script
Kyle
+1  A: 

The problem was the environment that the script execution process was running in. I changed some of the environment variables of the process and everything is working fine now. The script was initially a standalone shell script, but I wrote one script for each of the databases used. In order to control the workflow I wrote a web application for this which calls seperate threads for each script and can manage the threads. Thanks for the responses!

Kyle