0

I am calling a java program from shell script. Shell script contains one variable which needs to use in java program.

Shell Script:

for s in 0 1
do
javac -cp $CLASSPATH ./src/*.java
java -cp $CLASSPATH Test
done

Test.java

main() {
sValue = ...; // here I need to get value from shell
someMethod(sValue) {
. ... . 
}
}

shell script has variable s with value 0 and 1. I need to use this variable in java program Test.

In my program I am can't pass this value as argument as "java -cp $CLASSPATH Test $s". So please provide some other solution.

2 Answers 2

1

Propably (depends on shell) you will export the s variable to make it visible to the java process:

for s in 0 1
do
export V=$s
javac -cp $CLASSPATH ./src/*.java
java -cp $CLASSPATH Test
done

And then System.getenv("V") in Test.java.

Sign up to request clarification or add additional context in comments.

Comments

0

What you want is System.getEnv(...).

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.