Running python from Java using Process Builder -


for existing java code want extend, need run python code within java. using process builder this:

   processbuilder pb = new processbuilder("python", "/directorypath/mypython.py");    process p=pb.start();    bufferedreader stdinput = new bufferedreader(new                  inputstreamreader(p.getinputstream()));     bufferedreader stderror = new bufferedreader(new                  inputstreamreader(p.geterrorstream()));              // read output command             system.out.println("here standard output of command:\n");             while ((s = stdinput.readline()) != null) {                 system.out.println(s);             }              // read errors attempted command             system.out.println("here standard error of command (if any):\n");             while ((s = stderror.readline()) != null) {                 system.out.println(s);             }              system.exit(0);         } 

while code runs fine command line, in java "we need beautifulsoup, sorry" error. far understand,this means java environment missing sort of libraries code works command line.

do need send environment variables? if yes, , how?

i have 'beautifulsoup4' installed , up-to-date.

not definitive answer looks me problem in environment process runs in; missing environment variables expected python find "beautifulsoup4" extension.

a processbuilder has .environment() method returning map<string, string> keys environment variables , values variables' values. note modifying map alters environment! (the 1 of process launch, is).

try , print environment , compare when run command line.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -