LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 08:42 AM   #1
esolve
LQ Newbie
 
Registered: Oct 2012
Posts: 18

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, 09:13 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
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 09:16 AM.
 
Old 10-11-2012, 09:30 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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, 04:51 AM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
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



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 09:49 AM
How do i log GNU screen output to a file ? RadishTP Linux - Newbie 3 06-12-2009 02: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 09:32 PM
Can I show different output on the laptop screen and the external one? riwaJR Linux - Laptop and Netbook 9 11-14-2006 02:01 PM
Log Screen Output to a file sdandeker Linux - Newbie 3 09-17-2003 02:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 PM.

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
Open Source Consulting | Domain Registration