How to capture return value from java in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to capture return value from java in shell scripting
# 1  
Old 08-30-2009
How to capture return value from java in shell scripting

Hi All,

My shell script will call a java component with some arguments , the java component returns a string value to the shell script. How to assign the return value to the shell variable.

Here is the sample code.

In my shell script i am calling the java as fallows.

--exporting classpaths and relevant jar files

java com.sample.Demo arg1 arg2

Demo.java

has return value "myReturnValue"

How to handle this return value in the shell scripting.


Please help me it is argent.

Note Java takes arguments.

if it does not takes arguments below code is fine

ret_value=`java com.sample.Demo`
echo "$ret_value"
# 2  
Old 08-30-2009
If running:
Code:
ret_value=`java com.sample.Demo arg1 arg2`

Does not work then you could get the java script to save its output to a temporary file and then get the shell script to read in the contents of the file:
Code:
VARIABLE=`cat /tmp/temporary_file`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check if the JAVA Program is successfully executed in sh shell scripting

Hi , I have written a shell script to call a java program say load_id.sh .This sh script indeed is executed implicitly in other sh script which calls 2 more sh scripts one by one. I need to check if the load_id.sh (which calls java program) is executed successfully only then continue with... (1 Reply)
Discussion started by: preema
1 Replies

2. Shell Programming and Scripting

Shell Scripting | Return list of unique characters in files

Hi, I am trying to script the below, but I am not very good at it :( Your help would be greatly appreciated. 1. read all files in the directory in strings strings *.* 2. in each file, for each line that contains "ABCD", store characters located at position 521 and 522 of this line... (9 Replies)
Discussion started by: clippertm
9 Replies

3. Shell Programming and Scripting

How to capture script return code?

Hi I am executing database backup via shell script (Korn). The backup log is long, but I would like to capture only the last line so I can send an email if it fails Example of failed backup (only last 3 lines) BR0056I End of database backup: bejbofoh.aff 2012-07-26 07.31.21 BR0280I... (7 Replies)
Discussion started by: nimo
7 Replies

4. Shell Programming and Scripting

Shell Scripting Function call return value

Hi I have a function : Make_Report() { trx_report=`sqlplus -s $conn_str << @@ set echo off; set pages 0; set feedback off; set verify off; select srv_trx_s_no,... (1 Reply)
Discussion started by: neeraj617
1 Replies

5. Shell Programming and Scripting

PID Capture and Return Codes

I have a process that copies files from a main storage server to main other servers. We are attempting to speed up the processing and have thought that the best method would be to use concurrent file copying. What was suggested is that we change from using a simple RCP and waiting for it to... (3 Replies)
Discussion started by: dorrellg
3 Replies

6. Shell Programming and Scripting

reading fixed length flat file and calling java code using shell scripting

I am new to shell scripting and I have to to the following I have a flat file with storename(lenth 20) , emailaddress(lenth 40), location(15). There is NO delimiters in that file. Like the following str00001.txt StoreName emailaddress location... (3 Replies)
Discussion started by: willywilly
3 Replies

7. Shell Programming and Scripting

capture ftp return code..PLZ HELP

Hi all, i have written a code to ftp a file from one server to other.The ftp is happeneing successfully,but i am not able to capture the return code,to check if ftp has failed. plz help me to find out the return code....this is urgent below is the code i have written... (3 Replies)
Discussion started by: anju
3 Replies

8. UNIX for Dummies Questions & Answers

how to capture the return value in master script?

Hi, Here is my program that is returning a DATE: #! /usr/bin/ksh db=tcore_dev1 bteq <<end .logon $password_core .export report file=$BTEQ_OUTPUT_FILE_$$ select cast(add_months(cast(substr(cast(max(closedate) as varchar(10)),1,8)||'01' as Date),1)-1 as timestamp(0)) from $db.repo... (2 Replies)
Discussion started by: mahek_bedi
2 Replies

9. Shell Programming and Scripting

Capture Oracle return code in shell script

I am using the following code in my shell script list=`sqlplus -s $user/$pwd@$dbms<<EOF WHENEVER SQLERROR EXIT SQL.SQLCODE set pagesize 0 feedback off verify off heading off echo off select * from control_tbl where src_nm=$3 and extrct_nm=$4; exit SQL.SQLCODE; EOF` ERROR=$?... (1 Reply)
Discussion started by: Vikas Sood
1 Replies

10. Shell Programming and Scripting

Capture carriage return.

I try to test the carriage return in a variable. $ LENGTH=`expr $VARIABLE : ".*"` will return the length of the variable. But this doesn't work if $VARIABLE has zero length. Any help will be well appreciated. Thanks in advance. Giovanni (4 Replies)
Discussion started by: gio123bg
4 Replies
Login or Register to Ask a Question