Failed to set LD_LIBRARY_PATH for Java process

I am trying to call my linux executable from a shell script. Before calling this executable, I want to set LD_LIBRARY_PATH with specific values. My shell script looks like this:

Parent.sh (contains 2 lines)

   - source set_env.sh 
   - executable.so

Set_env.sh

   - setenv LD_LIBRARY_PATH /proj/something

When you manually run the Parent.sh script from the linux console, executable.so is called with LD_LIBRARY_PATH set correctly. But after integration with java code:

String[] commandArray ={"Parent.sh"};
Runtime runtime = Runtime.getRuntime();
Process javap = runtime.exec(commandArray);
javap.waitFor();

LD_LIBRARY_PATH is not set for executable.so

I hope that the description is clear :)

Please report what is wrong with the code.

+5
source share
2 answers

Dunes , . , , , Java-. , , , .

Runtime.exec(String[] cmd, String[] environment) (javadoc). , , .

ProcessBuilder API:

ProcessBuilder pb = new ProcessBuilder("executable.so");
Map<String, String> env = pb.environment();
env.put("LD_LIBRARY_PATH", "/proj/something");
Process javap = pb.start();
javap.waitFor();

, Java LD_LIBRARY_PATH.

+16

, csh? bash - , script ( IOException).

hashbang script, , .

.

#!/usr/bin/env csh
+1

All Articles