Register
It is currently Sun Sep 21, 2014 12:03 am

Java output into bash variable?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Feb 20, 2011 2:27 pm   

Joined: Sun Feb 20, 2011 2:25 pm
Posts: 1
I have a bash script that calls a java class method. The method returns a string to the linux console when run independently. how can I assign the value from the java method to a variable in a bash script?

running the script: java -cp /opt/my_dir/class.method [parameter]

output: my_string

if added in a bash script:

read parameter
java -cp /opt/my_dir/class.method [parameter] | read the_output
echo $the_output

the above doesnt work, I also tried unsuccessfully:
the_output=java -cp /opt/my_dir/class.method [parameter]
the_output=`java -cp /opt/my_dir/class.method [parameter]`
java -cp /opt/my_dir/class.method [parameter] 2>&1

How can i get the output stored into the_output variable?

thanks.


Top
 Profile  
 PostPosted: Sun Feb 20, 2011 11:16 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
either:
Code:
the_output=`java -cp /opt/my_dir/class.method [parameter]`

or:
Code:
the_output=$(java -cp /opt/my_dir/class.method [parameter])

should store the entire output of the java command to the_output


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP