| 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: 19216
|
|
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
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: 16687
|
|
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: 16687
|
|
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
|
 |
 |
|
|
subject: problem in standalone java returning value to shell script
|
|
|