it was stated that "to redirect Error to output std, you have to write the following code"
but if i changed the order as follows, only the output will be stored in the file:
my question is, how we can use the logic to describe this?
maybe i have miss understand the redirection char '>' concept. as i understand, it forwards the contents of some fd to other fd. ie, 2>&1 will forward the stderror to stdout and if we add ">logfile" the contents of stdout (which include stdout and stderr) will be redirected to the file, but that is not happened
can anyone explain the fd duplication, and how we can create fd (other than 0,1 and 2) and how we can deal with them.
i know it is a long question but i need some guides because man pages and info bash (Redirection section) make me confused.
generally the errors will be printed to the stderr.
In the first case at first you are redirecting the output to logfile file directly.
At this stage both the stdout and stderr are redirect to the logfile.
Then only redirecting the stderr to stdout.
(0 for stdin, 1 for stdout and 2 for stderr)
In the second case you are redirecting the stderr to the stdout.
So the error message is getting printed in the stderr and the stdout is redirected to the logfile.
So the output is stored in the logfile.
Last edited by thillai_selvan; 03-02-2010 at 04:18 AM..
You're storing all the output to a logfile.After that,you're specifying 2>&1,which means the messages in stder have to be stored in stdout.Now,stdout is logfile.So,both output and error are stored.
In the second case,you're redirecting the stderr to stdout.Then,you're redirecting the stdout to a file.Because,you specified that whatever printed in stderr should be printed in stdout and whatever printing in stdout should be transformed to the file.That's why error printing in stdout and the output is redirected to logfile. For more informations,refer the following URL. http://en.wikipedia.org/wiki/Redirection_(computing)
thanks for the reply, but if that is the case, how to know the flow of the command when there is multi redirection and piping?
from your answer, can i say that command stdout is redirected at the end of the command>? and stderr is redirected once it is received?
it is confusing thing, do u have a reference to that or guide? and what about creating and dealing with other FD?
From the second answer
Quote:
In the second case,you're redirecting the stderr to stdout.Then,you're redirecting the stdout to a file.Because,you specified that whatever printed in stderr should be printed in stdout and whatever printing in stdout should be transformed to the file.That's why error printing in stdout and the output is redirected to logfile
when i redirect stderr to stdout, is it like a pointer from fd 2 to fd1; in other words, whatever written to fd2 will be actually written to fd1. and once i write the content of fd1 (where the fd2 is also pointing) that will cause fd1 and fd2 contents to be written to file?
Last edited by ahmad.zuhd; 03-02-2010 at 04:27 AM..
i've checked the link, and it makes it better. but it doesn't include all the information. i'll continue searching the internet. However i have seen an example of creating a fd:
as in the page, this was intended to redirect the stdout to the fd 5 and create it, and close it. i have the following questions:
- what is exactly the meaning of second command? is it to redirect the command stdout "test" to the fd 5? and how i can see the contents of the fd 5?
- in the first command, why the < is used instead if > and what is the difference between the below two commands as in the info bash *Redirection section
The redirection operator
[N]<&WORD
is used to duplicate input file descriptors. If WORD expands to one
or more digits, the file descriptor denoted by N is made to be a copy
of that file descriptor. If the digits in WORD do not specify a file
descriptor open for input, a redirection error occurs. If WORD
evaluates to `-', file descriptor N is closed. If N is not specified,
the standard input (file descriptor 0) is used.
The operator
[N]>&WORD
is used similarly to duplicate output file descriptors. If N is not
specified, the standard output (file descriptor 1) is used. If the
digits in WORD do not specify a file descriptor open for output, a
redirection error occurs. As a special case, if N is omitted, and WORD
does not expand to one or more digits, the standard output and standard
error are redirected as described previously.
I have a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file.
Error output is getting copied to err file and getting displayed in console too. But... (2 Replies)
Greetings.
I am happily using constructs like the following; I have set -x to show fine distinctions.
$ exec 4> afile
+ exec
+ 4> afile
$ print -u4 This is the first line in afileAs you can see from the -x expansion, the shell performed the exec command and redirected file descriptor to... (4 Replies)
Hi,
I am trying to read a file line-by-line in a while loop, and perform some tasks which involves non-interactive SSH to a remote server. The code looks something like this --
#!/usr/bin/ksh
export myFile=/path/to/my/file.load
while read line
do
do something
## Adding the SSH... (2 Replies)
I am trying to use one global declaration --> "exec 2>$ERR" to capture all stderr outputs that may occur anywhere in my script.
Then close it at the end of the script using --> "exec 2<&-"
I am using KSH on Solaris 8.
KSH Version M-11/16/88i
If I comment two "exec .." statements in the... (11 Replies)
I have a file, let's say 1.jpg, and I have a text file that contains a list of filenames I would like to duplicate 1.jpg as (i.e., 2.jpg, 3.jpg, 4.jpg, etc.). The filenames that I want to create are all on separate lines, one per line.
I'm sure there's a simple solution, but I'm not claiming to... (7 Replies)
Hello All,
Im opening a file desciptor in perl and sending data using print CMD "$xyz".
is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)