How to call Java classes/methods from ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to call Java classes/methods from ksh
# 8  
Old 06-23-2006
Quote:
Originally Posted by girish.sh
Yes but from shell script, we call class like path/to/java classname

so if i want to call method classMethod, call will be like this?

"path/to/java classname.classMethod()"
Code:
class myClass
{
  public void myMethod ()
  {
     System.out.println ("From myMethod");
  }

  public static void main (String[] args)
  {
     myClass klass = new myClass();
     System.out.println ("From main");
     klass.myMethod();
  }
}

Thats how a class looks like. You can not call a method from the command line. All those calls should be done from within the class itself.
# 9  
Old 06-23-2006
Thanks Vino.

I have one more query, if one script calls another script, can the calling script get the return code from called script? return code maybe boolean or integer.
# 10  
Old 06-23-2006
In shell scripts, exit status is an integer. That integer can be a 0 for success and any other interger for failure. There is no concept of boolean as such. Unless you consider 0 and non-0 numbers.
# 11  
Old 06-23-2006
Vino,

Can we define exit status intereger values for our purpose excpet 0?

like can i set exit status:

"1" for error occured because of reason #1
"2" for error occured because of reason #2
...
# 12  
Old 06-23-2006
Quote:
Originally Posted by girish.sh
Vino,

Can we define exit status intereger values for our purpose excpet 0?

like can i set exit status:

"1" for error occured because of reason #1
"2" for error occured because of reason #2
...
Yes you can. The world is at your feet.
# 13  
Old 06-23-2006
But i guess there are some system define exit codes also...can we change them also? how we know that which exit codes are available for change from the range of 1-255?
# 14  
Old 06-23-2006
Hi.
I hope you do not mind, Vino. I'm going to aswer girish.sh for you. Smilie

- To get the exit status:
Suppose you call inside.sh in your script:
Code:
...
inside.sh
echo $?
...

The "echo $?" will echo the exit status of inside.sh, so $? variable will hold the exit status of the last executed command/script.

- You can "force" the exit statis of your scripts giving:
Code:
exit <N>

being <N> the number you want.

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Java Abstract Classes

Can anyone tell me if this is correct when creating classes in Java? public abstract class Animal { public class Point { public int x,y; } public class Animal { protected Point loc; protected String name; protected Random rng; String... (3 Replies)
Discussion started by: totoro125
3 Replies

2. Programming

Set java classes path

I add some new java jar files in the old project, how can I edit the class path? How can I compile all the java classes by just type 'C':o (3 Replies)
Discussion started by: Hscript
3 Replies

3. Shell Programming and Scripting

Script for adding few methods to bunch of Java files

Hi I have around 1000+ java file under different folder in /home/raxit/source and in each file i want to add a fix method. -------- /* Some comment for few lines like header block etc.. */ package import class A { method1 () { } method2 () (3 Replies)
Discussion started by: raxitsheth
3 Replies

4. Shell Programming and Scripting

Call java program from shell and pass values

Hi All, Can anybody please help me with how can i call my java program from shell and also pass parameter along with it so that the program can interpret the value/int and update the database. Thanks in advance Neha (1 Reply)
Discussion started by: Neha Goyal
1 Replies

5. Programming

Java can call C under Unix?

Under windows environment,I can compile C code into dll,then I can use Java to call this dll. I want to know whether Java can call C under Unix environment? How to do it? Where can I get example Java and C code? Thanks (1 Reply)
Discussion started by: konvalo
1 Replies

6. Shell Programming and Scripting

how to call java prog from shell script

I have a java program to validate a XML file. I want to call this java program in a shell script which will be registered as concurrent program in oracle apps. Can anyone please let me know the step by step appraoch required to call java program in shell script like ....intial steps... (1 Reply)
Discussion started by: kcp_pavan
1 Replies

7. Shell Programming and Scripting

call constructor of java class in script

Hi, Is it possible to call the constructur of a java class in a shell script? I know you can call static methods, but can you also call the constructor? tnx. (1 Reply)
Discussion started by: thebladerunner
1 Replies

8. Programming

how can compile cpp code containing references to java classes

hi there is example (on link given below )of such code that contains java class reference in c++ program. http://slackware.cs.utah.edu/pub/slackware/slackware-7.1/docs/Linux-HOWTO/Process-Monitor-HOWTO I am new in linux environment. and not able to compile it. when i compile it through... (1 Reply)
Discussion started by: surinder
1 Replies

9. Shell Programming and Scripting

Shell script to call multiple java commands

Hi, I want to call multiple java commands through a .sh file. I have drafted one with my least knowledge. But its not working. Pls help. I am trying to run this from Sun Solaris (OS 5.10) server with 10g oracle database. echo \* starting script AUTORUN echo \* get the Monitor path... (4 Replies)
Discussion started by: vivekdn
4 Replies

10. Shell Programming and Scripting

How to call Java by using shell script

Hi All, I am new to shell script, just wanted you guy to help. How do i call a java program by using shell script, pls give some samle code for it, thank you ver much. (2 Replies)
Discussion started by: aaabbb123123
2 Replies
Login or Register to Ask a Question