LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 09-07-2006, 03:14 AM   #1
montylee
Member
 
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168

Rep: Reputation: 30
Question 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
 
Old 09-07-2006, 03:58 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
You actually have the ingredients already
Just combine them:
Code:
make 2>&1 | tee build.log
Yves.
 
Old 09-07-2006, 04:50 AM   #3
montylee
Member
 
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168

Original Poster
Rep: Reputation: 30
Hey Thanks!!!
It worked flawlessly.

Actually i wasn't able to understand "2>&1"

Thanks a ton!

Regards,
montylee
 
Old 09-07-2006, 06:27 AM   #4
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Actually i wasn't able to understand "2>&1"

2>&1 Sends stderr (2) to stdout (1)
 
Old 09-07-2006, 11:58 PM   #5
montylee
Member
 
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168

Original Poster
Rep: Reputation: 30
Then why do we need '&'. Can't we achieve the same result with '2>1'?
 
Old 09-08-2006, 04:46 AM   #6
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
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.
 
Old 09-08-2006, 06:06 AM   #7
montylee
Member
 
Registered: May 2003
Location: India
Distribution: Ubuntu 7.04, Fedora Core 9
Posts: 168

Original Poster
Rep: Reputation: 30
Thumbs up

Yup, now i understand...
Thanks a ton for ur help!!!

GNU/Linux rocks!!!
 
  


Reply

Tags
mingw, redirection


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
shell script output to file drum2jc Linux - Software 1 05-30-2006 07:54 PM
Newbie No output from shell script nl1at Programming 2 04-04-2006 10:33 AM
Redirecting output of a shell script raj_deep2k1 Linux - General 2 01-20-2006 08:38 AM
shell script output redirection goral.j Programming 3 01-27-2005 06:34 AM
I/O redirection in a shell script gladeiator Programming 1 11-27-2003 02:35 PM


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