aspose file tools*
The moose likes Java in General and the fly likes Can executable jar return value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can executable jar return value?" Watch "Can executable jar return value?" New topic
Author

Can executable jar return value?

birenshah shahbiren
Greenhorn

Joined: Feb 28, 2008
Posts: 19
Hi All,

I have an executable jar, which is supposed to return a String value.
First of all, Is it possible?? If yes, how??

This jar will be called from VBScript program and I need the returned a string value to be used in VB Script.

Any help in this regrads will be appreciated.

Thanks,
Biren
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8206
    
  23

birenshah shahbiren wrote:I have an executable jar, which is supposed to return a String value.
First of all, Is it possible?? If yes, how??

Don't think so. Java programs can return numeric values, but these are generally used to indicate an error; and I certainly wouldn't use them for business logic.

What it (and any program, Java or otherwise) CAN do is write a String to a stream, such as stdout.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
birenshah shahbiren
Greenhorn

Joined: Feb 28, 2008
Posts: 19
Thanks Winston!

Writing it to a file is kind of last option, as jar file is going to return decrypted password.
Preference would be to store in cache or session.

Now the question arises, As application is not using any application/web server, is it possible to store thevalue in cache/session?
Second one, is registery a good option to store decypted password?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

Winston Gutkowski wrote:
Don't think so...
Winston

Actually yes. Executable and jar are red herrings.
Consider it as any other library on your class path, on whose class(es) you can invoke method(s) and that will return values.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1821
    
    7

I think Winston is assuming, as I am, that the JAR file will contain the Java program that is executed via the shell in VBScript, in which case: no you can't


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
birenshah shahbiren
Greenhorn

Joined: Feb 28, 2008
Posts: 19
Thank you for quick response, however it will be really great if any of you can give me the way to write a java program, which returns a String value when jar is called from VBScript
I believe, only that class from executable jar will be called which contains main() method.

Below is the working syntax for VBScript calling jar file:
createobject("wscript.shell").run "java -jar vbcall.jar " & dbPassword & " CipherText ", 0, True

I am still wating for the response, on possibility of jar returning a String value?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4463
    
    8

It can't return a String. The only return value of the java executable is an integer (generally zero for successful completion, non-zero in case of error).

As someone has already suggested, what you can do is write a Java program that will write to stdout - using System.out.println() statements. So you need a way of capturing that output in your VBScript. I'm sure that's possible, though I've no idea how because I don't know VBScript. But a quick Google gives a few useful looking links, for example: http://www.codescript.co.uk/run_command_capture_output.htm.
 
Consider Paul's rocket mass heater.
 
subject: Can executable jar return value?