Trouble with running java using Popen

Diez B. Roggisch deets at
Wed Jun 24 00:29:17 CEST 2009

Edward Grefenstette schrieb:
> 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:
>>>> os.chdir(pkgpath)
>>>> arglist = "java -Xmx1024m SemanticVectorsEvaluator ." + indexpath
>>>> SemVectPackage = Popen(arglist, stdout=PIPE, shell=True)
>>>> SemVectPackage.wait()
> 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.


More information about the Python-list mailing list