Trouble with running java using Popen

  • Thread starter Edward Grefenstette
  • Start date
E

Edward Grefenstette

I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:

Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Best,
Edward
 
N

norseman

Edward said:
I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:


Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Best,
Edward
=================
First glance shows you using ./ in code and ../in terminal. Might check
that first.

Second glance shows you using Popen vs popen (OK) but is that the
correct stdout? It is the CHILD's stdout that is being requested here.
(Probably what you had in mind, but ... is it?)

Third item - running from the terminal usually loads the terminal
environment. Running under program control may NOT load the environment.
This is a particular problem in Window$. Is the difference going to
effect your efforts?


As for Java specific problems (if any) I don't know. Another might.


Steve
 
C

Chris Rebert

I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:


Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

Have you tried?:

arglist = ["java", "-Xmx1024m", "SemanticVectorsEvaluator", "." + indexpath]
SemVectPackage = Popen(arglist, stdout=PIPE)
SemVectPackage.wait()

Cheers,
Chris
 
D

Diez B. Roggisch

Edward said:
I have a java prog I need to run at some point during the execution of
a python module.

The path to the folder containing the all the relevant java stuff
(which runs fine from the command line) is stored in pkgpath. The
relevant code is this:


Here indexpath is the path to a particular index file (usually
indexpath = "./indexfolder/fileindex"), so that effectively Popen
should be running the equivalent of the shell command:
-
java -Xmx1024m SemanticVectorsEvaluator ../indexfolder/fileindex
-
which, again, runs fine in the terminal.

However running the program returns the following error (echoed from
shell, doesn't interrupt prog):
-
Exception in thread "main" java.lang.NoClassDefFoundError:
SemanticVectorsEvaluator
-

I have no idea why this isn't working. Anyone have any suggestions as
to how I might troubleshoot this?

I'd say you got an CLASSPATH-issue here. You can add that explicitly via
env as argument to Popen, or pass it via commandline-args.

Diez
 
E

Edward Grefenstette

Bingo. I was running the python script in GNU script, and it wasn't
loading my bash config file properly. Have fixed it by
altering .screenrc and now the code runs fine. Would have never
guessed to look if you hadn't mentioned it, cheers!

Best,
Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top