LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-21-2009, 04:39 PM   #1
redss
Member
 
Registered: Jun 2003
Posts: 168

Rep: Reputation: 16
How to redirect stderr from piped output?


Assuming you dont have an executable called abcdef, the following writes an error message (like "command not found") to a file called myfile.out:
Code:
abcdef > myfile.out 2>&1
I want to see the output as it is written to the file, so I tried this:
Code:
abcdef | tee myfile.out 2>&1
What I want is for the stderr message to be redirected into myfile.out as well as stdout, but to be viewed as it generated (via the tee command), but the 2>&1 doesn't work in the above code.

How can I do this?
 
Old 08-21-2009, 04:44 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by redss View Post
Assuming you dont have an executable called abcdef, the following writes an error message (like "command not found") to a file called myfile.out:
Code:
abcdef > myfile.out 2>&1
I want to see the output as it is written to the file, so I tried this:
Code:
abcdef | tee myfile.out 2>&1
What I want is for the stderr message to be redirected into myfile.out as well as stdout, but to be viewed as it generated (via the tee command), but the 2>&1 doesn't work in the above code.

How can I do this?


Code:
abcdef 2>&1 | tee myfile.out
 
Old 08-21-2009, 04:50 PM   #3
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
Thanks!
 
  


Reply


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
Cannot redirect all stdout and stderr into file hawkgao Programming 2 05-12-2009 10:14 AM
redirect stderr to file with a prefix? JPMallory Programming 2 12-26-2007 04:10 PM
bash stderr redirect question code-breaker Linux - Software 1 08-06-2006 05:44 AM
how do i redirect stderr to a file? nodger Programming 5 11-28-2004 12:22 PM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 03:07 PM

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

All times are GMT -5. The time now is 07:59 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