You cannot pass anything but int as an exit parameter. This is true for all kinds of programs (corrent me, if I'm wrong).
If you want to have a string from a program, the most simple way is to make the java program print this to the standard output, and get it with the shell. For example:
A dummy java class:
public class dummyout {
public static void main(String[] args) {
System.out.println("Output string");
}
}
And the shell script:
#!/bin/bash
RESULT=`java dummyout`
echo "Result is: $RESULT"
Hope this helps.
What you have is quite different from what Lacel recommended. Do it exactly as suggested, probably adding "-classpath ${CLASSPATH}" between "java" and "dummyout"
When you write command such as:
RESULT=java -classpath ${CLASSPATH} dummyout
The shell interprets it as follows: Assign string "java' to shell variable "RESULT" and execute command "-classpath" with arguments "${CLASSPATH}" and "dummyout". Since "-classpath" is not a command you get the error. You should be glad, if there was command named "-classpath" it would have executed and you would have been even more confused.
When you do it as suggested:
RESULT=`java -classpath ${CLASSPATH} dummyout`
Then shell interprets it as: execute the command within back-quotes and assign its output(first word of the output actually, I think) to the shell variable RESULT. This is what you are looking for, Look at man pages of shell for more...
hth.;
The below thing is working:
Shell script:
#!/bin/ksh
javac TestEnvVarSet.java
typeset VAR=`java TestEnvVarSet`
echo $VAR
echo "Done"
Java:
public class TestEnvVarSet {
public static void main(String args[]){
System.out.println("test string");
}
}
I am wondering is there any approach for this. Thanks for all the help
Shyam
The below thing is working:
Shell script:
#!/bin/ksh
javac TestEnvVarSet.java
typeset VAR=`java TestEnvVarSet`
echo $VAR
echo "Done"
Java:
public class TestEnvVarSet {
public static void main(String args[]){
System.out.println("test string");
}
}
I am wondering is there any other approach for this. Thanks for all the help
Shyam