• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Java program from Non-Java code

 
mini mehta
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is there any way to call java code from non-java and return a exit code from java program to non-java program.

example calling a java batch program from a shell script.

Thanks
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

You can call your java program just like any other program.
To return a status code to the calling program, use System.exit(n).

Regards, Jan
 
rohit leeta
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Jan's solution does not work for you you can learn JNI api. It allows you to crease a JVM and run Java programs from C/C++ programs.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mini mehta:
Hi

Is there any way to call java code from non-java and return a exit code from java program to non-java program.

example calling a java batch program from a shell script.

Thanks


You could have a java function called from your program through the use of JNI
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was aiming for the simplest solution, because the requestor was asking for a shell script example.

The shell script could look like this (unix-like pseudocode):
where the environment variable $? holds the value returned by the java program.

Regards, Jan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic