Bash malfunction, or something else ??
David Curry
dsccable at comcast.net
Tue Jan 25 05:22:58 UTC 2005
Nifty Hat Mitch wrote:
>On Mon, Jan 24, 2005 at 12:06:49AM -0500, David Curry wrote:
>
>
>>Richard Hubbell wrote:
>>
>>
>>>On Sun, 23 Jan 2005 22:44:09 -0500, David Curry <dsccable at comcast.net>
>>>
>>>
>.....
>
>
>>>Capture stdout and stderr to a file and see if that is what you expect.
>>>
>>>cdrecord -scanbus 2>&1 myfile
>>>
>>>
>>>
>....
>
>
>>>>There are six more lines of output sent to the display screen than are
>>>>sent to a file via use of the > [filename] option in BASH.
>>>>
>>>>
>....
>
>
>>Thanks, Richard. As far as I knew all cdrecord -scanbus output was
>>displaying on my monitor (stdout) and did not know that the first four
>>lines omitted from the disk file I created were "errors" (scsidev: "ATA"
>>--> Linux sg driver version: 3.5.27).
>>
>>Following Up on the suggestions of Jason Tibbits and Jim Cox, I repeated
>>the exercise using &> instead of just > and the file produced included
>>all of the missing lines.
>>
>>Thanks again to all who responded.
>>
>>
>
>One key point here is that when a process is launched it will
>commonly have three file descriptors by default.
>
> standard input #-0
> standard output #-1
> standard error #-2
>
>By convention stdout is used for the 'usefull' output
>and stderr is for the 'exceptional' stuff. See exec().
>
>"C" programmers, see also 'dup()' and 'dup2()'.
>
>It is common to redirrect the various file descriptors.
>
>This merges stderr on file handle 2 to file handle 1 (stdout).
>
> 2>&1
>
>Or the error and output streams can be seperated/ isolated
>into files.
>
> wc /etc/* > /tmp/junk 2> /tmp/error-junk
>
>Recall that child processes can inherit file descriptors
>from the parrent process. This makes it possible to do
>something like:
>
> make something-large > /tmp/make-out 2> /tmp/make-err &
>
>Note that make may invoke a thousand processes and as long as the make
>files do not do strange things you can....
>in two different windows watch them both.
>
> tail -f /tmp/make-out
> tail -f /tmp/make-err
>
>There is also "tee" that can be used to fiddle with IO.
>
>It is also common for modern programs to 'test' their file
>descriptors. See isatty()... Many common programs do act differently
>if you redirrect IO to a file.
>
>For example "\ls --color=tty / " will not emit the escape characters
>needed to color the terminal. This type of test can cause confusion
>for QA folks and others.
>
>Also there is the issue of the LANG environment variable....
>
>
>
>
Thanks for the info, Tom.
More information about the users
mailing list