Problem with call of Java Programm & return code handling & output to several streams.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with call of Java Programm & return code handling & output to several streams.
# 1  
Old 05-18-2011
Problem with call of Java Programm & return code handling & output to several streams.

Hello Everybody,
thanks in advance for spending some time in my problem.
My problem is this:
I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file.

The following code doesn't work right, because in the if construct it checks if de 'tee' command did work.

PHP Code:
if ( java -cp .:./lib/*.jar:./lib/*.jar:./lib/*.jar:./lib/*.jar *.*.* $*  | tee -a $PathToLog ) 
could you igamine what solution could solve my problem? (the java command itself works, the stars are only for anonymize)

thanks a lot

danifunny
# 2  
Old 05-18-2011
This should work, though the processing would happen before displaying the output:
Code:
if java ... > TEMP.FILE; then
    # Process success
fi
cat TEMP.FILE | tee -a $PathToLog
rm -f TEMP.FILE

Or this would keep things in order:
Code:
java ... > TEMP.FILE
result=$?
cat TEMP.FILE | tee -a $PathToLog
rm -f TEMP.FILE
if [ $result = 0 ]; then
    # Process success
fi

Or, if the processing produces no output, you might do this:
Code:
if java ... ; then
    # Process success
fi | tee -a $PathToLog

# 3  
Old 05-18-2011
Quote:
Code:
if java ... ; then
# Process success
fi | tee -a $PathToLog
This works - after a first test - fine for me, the 2 other solutions don't fit my needs for this script, but maybe i'll use them another time Smilie. Thanks a lot!

After some own research today, i came across this solution:
Code:
set -o pipefail

if ( java .... ) | tee -a $PathToLog
then  # Process succes
fi

Can you think of what solution of these two would be the best one?

thanks and greets
danifunny
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Passing Username & password through shell script to java code

Hi, I have a shell script (script.sh) in which we are calling java code which asks for Username: Password: for authentication purpose currently we are passing the credential manually and run the script. but I am trying echo -e "user_id\npassword" | script.sh but its not... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

3. Shell Programming and Scripting

If && command giving wrong output

Hi All, I am trying to run a script which will search for 2 strings(stopped,started) in a text file and echo an output depending on below condition -bash-3.2$ cat trial1.txt v ggg f -bash-3.2$ cat trial1.sh VAR9=` grep 'stopped' /tmp/trial1.txt` VAR10=` grep 'started'... (4 Replies)
Discussion started by: srkmish
4 Replies

4. UNIX for Dummies Questions & Answers

Handling return & exit statements

I have 2 shell scripts the primary one would load the other one which will have functions defined in it. Script 1: . /apps/bin/Script 2 function if then continue... .... fi Script 2: function() (10 Replies)
Discussion started by: Ariean
10 Replies

5. UNIX for Dummies Questions & Answers

Compile & Run Java Code

The java program is a part of speech tagger -> The Stanford NLP (Natural Language Processing) Group The goal is to use this script as part of a webpage to tag parts of speech based on a user-inputted string. I have no idea what to do with the files - I'm a complete *nix noob. I tried running... (4 Replies)
Discussion started by: tguillea
4 Replies

6. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

7. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

Hi friends, I have a script that sets the env variable path based on different conditions. Now the new path variable setting should not done in the same terminal or same shell. Only a new terminal or new shell should have the new path env variable set. I am able to do this only as follows: >cd... (1 Reply)
Discussion started by: sowmya005
1 Replies

8. Linux

Having player problem && need your help.

My System is FC3, The following Players don't run well: 1).Helix Player couldn't play MP3 and *.wma files, 2).Totem is the same, 3)XMMS couldn't play .wma files. I am a newer of Linux,but I like Linux,just as you. Could you help me? Thank you! (1 Reply)
Discussion started by: letcorpmuv
1 Replies

9. Shell Programming and Scripting

problem w/ -z && -n switches in an if statment

When ever i run this if statement with the -n OR -z switches it always returns says positive and does "HAVE STUFF". BUT the file does not contain the word optimus in any form. $echo this is mojo > test.file $if ; then >echo HAVE STUFF >else^Jecho NO STUFF >fi HAVE STUFF $if ; then... (1 Reply)
Discussion started by: Optimus_P
1 Replies
Login or Register to Ask a Question