Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:05:28+00:00 2026-05-28T17:05:28+00:00

I am trying to call my linux executable from shell script. Before calling this

  • 0

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

Parent.sh (contains 2 lines)

   - source set_env.sh 
   - executable.so

Set_env.sh

   - setenv LD_LIBRARY_PATH /proj/something

On manually executing Parent.sh scipt from linux console, the executable.so is called with LD_LIBRARY_PATH set correctly. But after integrating it wiht java code as:

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 description is clear 🙂

Please let know whats wrong in the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:05:29+00:00Added an answer on May 28, 2026 at 5:05 pm

    Dunes answer solves your problem, but I would strongly suggest a different approach in this particular case. Instead of relying on a shell to set the environment arguments, you should do this in your Java code. This way you don’t need to know which shells exist on the system and what their language is, it will just work on all platforms.

    To do this, you can use the Runtime.exec(String[] cmd, String[] environment) overload (javadoc). As the second parameter you can pass an array which contains all the environment variables the subprocess will see.

    A little bit nicer even is the 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();
    

    This way, the subprocess will inherit all environment variables from the Java process, and additionally have the LD_LIBRARY_PATH variable set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call a shell script that sets a bunch of environment
I'm trying to call the Matlab engine programatically from a C program on Linux
I'm trying to call a web service from Excel 2003 module. The way i've
I'm trying to test the sendfile() system call under Linux 2.6.32 to zero-copy data
I am trying to call Matlab functions from C++ code. With Matlab it comes
I'm trying to understand the system call interface and implementation in the Linux kernel.
I am trying to understand how the linux syscall sched_setaffinity() works. This is a
I'm trying to print call stack from within a program. Unfortunately, call to glibc
I am trying to spawn a new process using execve() from unistd.h on Linux.
I am running a Linux box running 2.6.9-55.ELsmp, x86_64. I am trying to set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.