File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes problem in standalone java returning value to shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem in standalone java returning value to shell script" Watch "problem in standalone java returning value to shell script" New topic
Author

problem in standalone java returning value to shell script

Murthy Manchala
Greenhorn

Joined: Aug 20, 2008
Posts: 21
I am trying to send password to a shell script to run batch jobs.

I am not able to send password to shell script via java standalone application. the java main method cannot return value as its return type is "VOID". please advice me how i can get password in shell script though java standalone.

Due to security i can't use system out or i can't write to a file.


I saw below code in google but its not working for me
Test.java:



Thanks
Murthy
Murthy Manchala
Greenhorn

Joined: Aug 20, 2008
Posts: 21
If i use above code and run the script as

./test.sh

Its not showing any thing.

Thanks
Murthy.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

That's because the only way to make any Java output anything is using System.out, System.err or System.console() (if available). However, you're explicitly forbidden to use any of these. Therefore you simply cannot do what you need to do.

It's like asking you to tighten a screw without letting you use a screw driver, coin or anything else you can use to tighten a screw.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Murthy Manchala
Greenhorn

Joined: Aug 20, 2008
Posts: 21
Rob,

Due to security reasons i can't use system.out or system.err. I should not print the password. is there any way i can get the password in shell script.


Thanks in advance.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18977
    
  40

Murthy Manchala wrote:
Due to security reasons i can't use system.out or system.err. I should not print the password. is there any way i can get the password in shell script.


It's pretty simple. If the password can't leave the java program -- system out, files, network, etc. -- it can't get to the shellscript.

Your best option is to move (port) the code that needs the password (in the shellscript), into the java program.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Murthy Manchala
Greenhorn

Joined: Aug 20, 2008
Posts: 21
Henry,

except the system.out what are the options i have. I can't write password to a file. is the system.set property works. if it works can you please give me sample code

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18977
    
  40

Murthy Manchala wrote:is the system.set property works. if it works can you please give me sample code


No. Shellscripts runs programs in a subshell, so environment variables won't take.... and even if you could, don't the same security restrictions (intent) apply?

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in standalone java returning value to shell script