0

I need to call a bash script in java class . Before calling the bash script , few variables need to be exported. So when bash script is executed. It's should get the required exported values.

class Javapgm {

public static void main(String [] args){

//export VAR=10

//Call bash script script.bash so that it can use this VAR

}

}

1 Answer 1

3

To execute a bash script, use ProcessBuilder.
To set environment variables, call environment().

ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", "script.bash");
pb.inheritIO();
pb.environment().put("VAR", "10");
Process p = pb.start();
p.waitFor();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.