aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript 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: 2510
    
  10

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: 6662
    
    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: 2510
    
  10

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling Java program from Non-Java code