• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How return a string from java program to the shell which invokes thee java command

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an encryption program completely written in java , which will ecnrypt and decrypt the password.

But after decryption it should return the decrypted password to the SHELL script where we issue java command , so that that decrypted password can be stored in the variable in the shell script.

Also i m little bit confused about invoking java program form shell script and storing the return value in the variable like below.
password1=java EncryptProgram
considering EncryptProgram as java Class file.

can any one help me to do this.

Thanks in advance.

Sekhar.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You did not say which shell you are using so I will assume the bash shell. You could try this:

password1=`java EncryptProgram`

Those are backward-ticks around the java command. Then have your program write to System.out.
 
Sekhar Choudary
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , thanks peter for valuable information, i m using bash shell.

i have decryptPassword() method from that method i need get the ecnrypted password which can be stored in password1 variable in shell script.

my program looks like below

import stuff here;
public class EncryptAndDecrypt{

public static void main(String args[] ){

------------
-------
checkUserExistence();
encryptPassword();
decryptPassword(); //the decrypted password in this method should get stored in "password1" variable in shell script.

}

public static void checkUserExistence(){ ------------}
public static void encryptPassword(){
// This will encrypt and stores the password in the pasword config file
}

public static void decryptPassword(){
//This will decyrpt and prints the password.
// REQUIREMENT is the decrypted password should get stored in "password1" varaiable in the shell script.
/}

}//class

Can anyone help me in this regard.

Thanks,
Sekhar.




 
Sekhar Choudary
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Otherwords , here is my shells script

ed.sh
-----
#!/bin/bash
PATH=$PATH:/opt/was61/WebSphere/AppServer/java/bin
CLASSPATH=/opt/was61/WebSphere/AppServer/java/lib:/tmp/ch:.:$CLASSPATH
echo 'Shell script to execute encryption program'
echo 'enter username'
read user

password1=java -cp $CLASSPATH GetThePassword $user
echo $password1

---------
When we ran tha above ed.sh it's showing the following error.


./ed.sh: line 8: -cp: command not found

Can anyone solve this problem.

When i remove "password1" in the below line

password1=java -cp $CLASSPATH GetThePassword $user

It's working fine.

but i want to store the result of into password1 variable.

Thanks ,
Sekhar.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My previous post contains the solution to the "./ed.sh: line 8: -cp: command not found" problem. Go and read it again and then tell me what is missing from this script line:

password1=java -cp $CLASSPATH GetThePassword $user
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have similar requirement but with a small change.My java program is running on a remote machine instead of on local machine.I want to call this program from a remote unix machine and need to get a string to be returned from java program.How can I change the shell script for this.I appreciate any help.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jagan, welcome to Java Ranch!

Please do not hijack someone else's topic - instead open a new topic and ask your question there.
 
Whatever. Here's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic