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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-07-2006, 02:14 AM
|
#1
|
|
Member
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168
Rep:
|
Output and Error redirection in Shell script (MinGW)
Hi,
I want to have a shell script in which i compile a project using the 'make' command and i want to write the entire output including the make output and errors to a log file as well as display it on the standard output. On GNU/Linux, the following syntax works properly:
$ make |& tee ./build.log
On windows, using MinGW, the above command gives an error, so i use the following command:
$ make | tee ./build.log
So, i have removed the '& from the above command.
But this command only writes the output of the make command to the log file. If i use the following command, then the log file is properly produced but nothing is written on the output:
$ make > ./build.log 2>&1
How can i write the entire output including the make output and errors to the output stream as well as the log file on the MinGW shell?
Thanks in advance!!!
Regards,
raman
|
|
|
|
09-07-2006, 02:58 AM
|
#2
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
You actually have the ingredients already 
Just combine them:
Code:
make 2>&1 | tee build.log
Yves.
|
|
|
|
09-07-2006, 03:50 AM
|
#3
|
|
Member
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168
Original Poster
Rep:
|
Hey Thanks!!!
It worked flawlessly.
Actually i wasn't able to understand "2>&1"
Thanks a ton!
Regards,
montylee
|
|
|
|
09-07-2006, 05:27 AM
|
#4
|
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
Actually i wasn't able to understand "2>&1"
2>&1 Sends stderr (2) to stdout (1)
|
|
|
|
09-07-2006, 10:58 PM
|
#5
|
|
Member
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168
Original Poster
Rep:
|
Then why do we need '&'. Can't we achieve the same result with '2>1'?
|
|
|
|
09-08-2006, 03:46 AM
|
#6
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
2>1 would mean redirect errors (2) to file named "1".
2>&1 means redirect errors (2) to an existing descriptor (&) the number of which is 1.
Yves.
|
|
|
|
09-08-2006, 05:06 AM
|
#7
|
|
Member
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168
Original Poster
Rep:
|
Yup, now i understand...
Thanks a ton for ur help!!!
GNU/Linux rocks!!!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:58 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|