LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-11-2012, 09:42 AM   #1
esolve
LQ Newbie
 
Registered: Oct 2012
Posts: 16

Rep: Reputation: Disabled
how to show output and error on the screen and put them to log file


I want to run a program which will show output and error on screen
I also want to put them into file while being shown on the screen
I tried tee but the results are always not as expected
 
Old 10-11-2012, 10:13 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 640

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Hi.

You should redirect standard error to standard output before using tee. For example in bash:
Code:
<program> 2>&1 | tee logfile
In recent versions of bash there is a shorthand for this operation:
Code:
<program> |& tee logfile

Last edited by firstfire; 10-11-2012 at 10:16 AM.
 
Old 10-11-2012, 10:30 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,612

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
Without more information on what you have already tried, it's hard to give advice. Here's what I would try first:
Code:
some_program arg1 arg2 2>&1 | tee some_file
Output buffering can be an issue when a program's output that would normally go to a terminal is redirected somewhere else, such as to a pipe. Output that is going to a terminal is, by default, line buffered, whereas output (other than stderr) not going to a terminal is block buffered (typically 4KB blocks). That can result in messages and regular output not appearing in the same sequence they would when everything is going directly to a terminal. Workarounds for that depend on what program you are running, and include:
  1. In a C program, calling setbuf(3) to override the default buffering behavior,
  2. Using a specific flag argument to override buffering in programs that have that feature (e.g., the "--line-buffered" option in grep),
  3. Using the unbuffer utility (part of the expect package.
 
Old 10-12-2012, 05:51 AM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by esolve View Post
I tried tee but the results are always not as expected
What do you mean by:„…but the results are always not as expected“?

What do you see on screen and what is in the file?
 
  


Reply

Tags
output, tee


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clean Up Log - Search for Pattern in Log file and Output result bridrod Linux - Newbie 10 01-05-2010 10:49 AM
How do i log GNU screen output to a file ? RadishTP Linux - Newbie 3 06-12-2009 03:35 PM
Log in screen won-t show up, I get a black screen and mouse pinter on waiting mode Nis2k Linux - General 1 03-26-2008 10:32 PM
Can I show different output on the laptop screen and the external one? riwaJR Linux - Laptop and Netbook 9 11-14-2006 03:01 PM
Log Screen Output to a file sdandeker Linux - Newbie 3 09-17-2003 03:57 AM


All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration