- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- command | tee -a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 06:13 AM
тАО05-19-2009 06:13 AM
Here my command:
java -jar example.jar | tee -a /tmp/aa.log
echo $?
The problem here is that $? is always 0, of course, because the last command is tee (not my java command). How to catch the return value code for java command ?
Bests regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 06:20 AM
тАО05-19-2009 06:20 AM
Re: command | tee -a file
java -jar example.jar >> /tmp/aa.log 2>&1
echo $?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 06:22 AM
тАО05-19-2009 06:22 AM
Re: command | tee -a file
No I need the tee ....
Bests Regards
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 06:52 AM
тАО05-19-2009 06:52 AM
Re: command | tee -a file
java -jar example.jar | tee -a /tmp/aa.log
echo $PIPESTATUS
PIPESTATUS
An array variable (see Arrays below) containing a list of exit status values from the processes in the most recently-executed foreground pipeline (which may contain only a single command).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 03:41 PM
тАО05-19-2009 03:41 PM
Re: command | tee -a file
UNIX RETURN CODE PRIMER
[tested on Red Hat Linux using bash-2.05]
In the examples below:
- it is assumed that you want to both display the output of the command (ls) and capture the exit code (a.k.a. return code value) in a variable (rc).
- a return code value other than "1" means the script did not work correctly.
# Basic (correct)
$ ls nonexistent 2>&1; rc=$?; echo $rc
ls: nonexistent: No such file or directory
1
# Capture return code after pipe (wrong)
$ ls nonexistent 2>&1 | tee -a /dev/null; rc=$?; echo $rc
ls: nonexistent: No such file or directory
0
# Capture return code after command (wrong)
$ ls nonexistent 2>&1; rc=$? | tee -a /dev/null; echo $rc
ls: nonexistent: No such file or directory
<-- blank
# Capture return code after command run in subshell (wrong)
$ (ls nonexistent 2>&1; rc=$?) | tee -a /dev/null; echo $rc
ls: nonexistent: No such file or directory
<-- blank
# Use I/O redirection with extra file descriptors (correct)
$ exec 3>&1; rc=`exec 4>&1; (ls nonexistent 2>&1; echo $? >&4) | tee -a /dev/null >&3`; exec 3>&-; echo $rc
ls: nonexistent: No such file or directory
1
# bash v2.0+ offers an easy-to-use PIPESTATUS array (correct)
$ ls nonexistent 2>&1 | tee -a /dev/null; echo ${PIPESTATUS[0]}
ls: nonexistent: No such file or directory
1
Regards,
Jared
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-19-2009 09:47 PM
тАО05-19-2009 09:47 PM
Re: command | tee -a file
If you dont want to show your output or first command then no need to give tee command.
tee command is showing the output of first command and send the same thing into the output file.
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2009 04:19 AM
тАО05-20-2009 04:19 AM
SolutionAnother way (using a temporary file):
# (ls nofile 2>&1;echo $? > /tmp/rc.$$)|tee -a /dev/null;echo $(
Also, Den, please don't forget to evalulate the responses to some of your previous questions:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1335784
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2009 11:30 AM
тАО05-20-2009 11:30 AM
Re: command | tee -a file
rc=$({ { your-command ; echo $? 1>&3 ;} | tee -a output.txt 1>&2 ;} 3>&1) 2>&1
echo "rc=$rc"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2009 10:32 AM
тАО05-25-2009 10:32 AM