my dog learned polymorphism*
The moose likes Java in General and the fly likes Calling Java program from Non-Java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling Java program from Non-Java code" Watch "Calling Java program from Non-Java code" New topic
Author

Calling Java program from Non-Java code

mini mehta
Ranch Hand

Joined: Oct 22, 2000
Posts: 120
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

Joined: Dec 20, 2006
Posts: 2491
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
rohit leeta
Ranch Hand

Joined: May 02, 2007
Posts: 49
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.


<a href="http://www.java-forums.org" target="_blank" rel="nofollow">Java Forums</a>
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Calling Java program from Non-Java code
 
Similar Threads
Calling java program from groovy...
kickin off a script from java
Calling a URL
Thread Question.
How to interact with bash?